web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

In project Operations I am not able to populate the field value in the views

(2) ShareShare
ReportReport
Posted on by 10
I am having an issue with populating a field in my view. I created a custom field "Charge code" in the Actual Entity to fetch the value from Project Entity and populate in the Actual entity  in Project Operations. I can confirm the Java script is grabbing the appropriate value from the project entity and populating in the Actual entity. Value is populating in the view when I open the record and closing it , the only part that does not work is it is not auto populating in the Active Actuals view.  Does anyone have any insight on this? I am sharing the Java script code below: Please help me to resolve this..
 
function populateChargeCodeFromProject(executionContext) {
    var formContext = executionContext.getFormContext();
    // Get the selected Project from the lookup field
    var projectLookup = formContext.getAttribute("msdyn_project").getValue();
    if (projectLookup && projectLookup[0]) {
        var projectId = projectLookup[0].id.replace(/[{}]/g, ""); 
        // Retrieve Charge Code from Project entity
        Xrm.WebApi.retrieveRecord("msdyn_project", projectId, "?$select=tcg_chargecode").then(
            function success(result) {
                var chargeCode = result.tcg_chargecode;
                if (chargeCode !== null && chargeCode !== undefined) {
                    // Set the Charge Code in Actuals entity form
                    formContext.getAttribute("tcg_chargecode").setValue(chargeCode);
                    formContext.getAttribute("tcg_chargecode").setSubmitMode("always");
                    // Save the form (this updates the database)
                    formContext.data.entity.save();
                    // Update the record in the database directly
                    var recordId = formContext.data.entity.getId().replace(/[{}]/g, "");
                    var entityName = formContext.data.entity.getEntityName();
                    var data = { "tcg_chargecode": chargeCode };
                    Xrm.WebApi.updateRecord(entityName, recordId, data).then(
                        function success(result) {
                            console.log("Charge Code updated successfully in database.");
                            // Force a refresh of the Active Actuals View
                            Xrm.Utility.refreshParentGrid();
                        },
                        function error(error) {
                            console.error("Error updating Charge Code:", error.message);
                        }
                    );
                } else {
                    console.warn("Charge Code not found in Project entity.");
                    formContext.getAttribute("tcg_chargecode").setValue(null);
                    formContext.data.entity.save();
                }
            },
            function error(error) {
                console.error("Error retrieving Charge Code:", error.message);
            }
        );
    } else {
        console.warn("No Project selected.");
    }
}

 
I have the same question (0)
  • Suggested answer
    Holly Huffman Profile Picture
    6,538 Super User 2025 Season 2 on at
    Good morning, afternoon, or evening :) depending on your location!
    Hope you are well today.
     
    The issue you're describing, where the value is not auto-populating in the Active Actuals view, typically relates to a disconnect between the form-level updates and the view-level data refresh in Dynamics 365 Project Operations. Here's how you can address this:
    Steps to Resolve:
    1. Ensure Field Visibility in the View:
      • Confirm that the "Charge code" field (tcg_chargecode) is included in the Active Actuals view. Navigate to the view configuration and verify its presence.
      • If it's missing, add the field and publish the changes.
    2. Trigger View Refresh Programmatically:
      • While the script already calls Xrm.Utility.refreshParentGrid(), ensure this function is firing correctly. Sometimes, timing issues can cause the grid to fail to refresh.
      • You can try adding a small delay before calling the refresh function:
        setTimeout(() => {
            Xrm.Utility.refreshParentGrid();
        }, 1000); // 1-second delay
    3. Check Save and Submit Logic:
      • Verify that the formContext.getAttribute("tcg_chargecode").setSubmitMode("always"); and formContext.data.entity.save(); methods are successfully committing the value to the database.
      • If the form isn't saving correctly, the view won't update because the data isn't propagated to the Actuals entity.
    4. Enable Automatic View Refresh Settings:
      • Dynamics 365 has a cache mechanism for views, and sometimes changes made programmatically to entity records do not reflect immediately.
      • To ensure automatic refresh, consider configuring the record update logic using workflows or plugins instead of relying on JavaScript.
    5. Validate Data Context:
      • Confirm that the Active Actuals view is pointing to the right dataset in Dataverse. If there are filters applied to the view, ensure the record updates are not excluded inadvertently.
    6. Browser Cache and User Sessions:
      • Ask users experiencing the issue to clear their browser cache and reload the CRM page.
      • Random failures like these can sometimes be session-related.
    7. Server-Side Solution:
      • If JavaScript alone doesn't resolve the issue, consider implementing a plugin or Power Automate flow to handle the "Charge code" synchronization between entities server-side.
    Additional Tips:
    • Test this script and functionality in multiple environments (e.g., Dev, UAT) to confirm its behavior across deployments.
    • Review the browser console logs for any warnings or errors when executing the script.
     
     
    Hope this helps!
  • Suggested answer
    Krishna Acharya Profile Picture
    123 on at

    Thanks for sharing the details — you're really close to the solution!
    From what you've described, the custom JavaScript is working when the form is opened, but the "Active Actuals" view isn't auto populating the Charge Code field unless the record is opened and closed. This is a common scenario in Dynamics 365 / Project Operations due to when and how the data gets persisted and indexed for views.

    Recommended Fixes:
    1. Use a Power Automate Flow or Plugin instead
    • Instead of relying on JavaScript in the form, use a Power Automate flow or a server-side plugin to copy the Charge Code from the Project to the Actual record when the Project is linked.
    • This ensures the value is persisted to the database immediately — and will be visible in views without needing to open the record manually.
    2. Trigger JavaScript on Field Change + Save
    • Make sure your script is bound to the msdyn_project field’s OnChange event and to the form’s OnLoad.
    • Also, ensure autosave is enabled and the entity’s save is triggered (looks like you're doing this already, but double-check if the actual record is being saved server-side).
    3. Use Business Rules or Workflows for Reliability
    • If you’re not comfortable with plugins/flows, try a Business Rule that sets Charge Code when Project is set — though this might still need the form to be opened.
    I used AI to help craft rephrases this response and share some useful tips for your Dynamics 365 challenge.
    If its helpful to you please Mark as verified
    Thanks,
    Krishna

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 33 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans