Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Updating fields in a Form interactively - Real Time Workflow, JavaScript, Action?

(0) ShareShare
ReportReport
Posted on by 66

Hi All,

I am hoping to get steered in the right direction.

Install is Dynamics 365 Online. I have a Case Entity which has to grab 3 pieces of data from a Customer Asset (Customer Equipment) entity when the Case is first created by a User.

The first field to be filled in is the Customer Asset name which is manually selected by the User via a Lookup field which presents a list of the available Customer Assets linked to the Customer Account. This all works OK.

What I would like to happen next if that when the user has selected the correct Customer Asset that the Model Name & Serial Number fields (which are also part of the Customer Asset record) get filled in automatically in front of the user. 

I can think of a number of possible ways to do this involving a Real Time Workflow, JavaScript, Actions (or a mixture of these) but I am struggling to decide which is the best approach.

Can anybody offer some suggestions please?

I am particularly keen to find out if a Real Time workflow can "interactively" update values on a Screen in front of a User. Would this require a screen refresh (F5) to be initiated? i.e. the Real Time work needs JavaScript to be involved to get the job done?

Thanks

*This post is locked for comments

  • Verified answer
    David Brooker Profile Picture
    66 on at
    RE: Updating fields in a Form interactively - Real Time Workflow, JavaScript, Action?

    For anybody that follows:

    Following Radu's suggestions I looked at:

    Business Rules - Will be very useful for the future but it appears that these are limited to one entity only i.e. you can only affect the fields on the Form which is displayed in front of the user. You cannot "Reach Out" into related Entities

    Using JavaScript and the WebAPI suggested by Radu (My install is a Version 9 Dynamics CRM Online) I came up with the code below:

    //retrieve data from Customer Asset record based on entity id provided by LookUp field
    function retrieveEquipmentDetails() {
      //read value of lookup field (lookup field points to Customer Asset)
      if (Xrm.Page.getAttribute("new_customerequipment").getValue() != null && Xrm.Page.getAttribute("new_customerequipment").getValue()[0].id != null) {
        var customerassetid = Xrm.Page.getAttribute("new_customerequipment").getValue()[0].id;
     
        //pass the Customer Asset entity ID and Entity type so as to retrieve the 2 x customer Asset fields
        Xrm.WebApi.retrieveRecord("msdyn_customerasset", customerassetid, "?$select=new_mach1meterno,new_machinetype1").then(
          function success(result) {
            if (result != null) {
              //set machine meter number text field
              if (result.new_mach1meterno != null)
                Xrm.Page.getAttribute("new_equipmentserialnumber").setValue(result.new_mach1meterno);
              //set machine type optionset field
              if (result.new_machinetype1 != null)
                Xrm.Page.getAttribute("new_machinemodeltype").setValue(result.new_machinetype1);
            }
          },
          function(error) {
            alert(error.message);
           }
        );
      }
    }

    It works well. The key to understanding the code above is that you use a LookUp field which points back to the Customer Asset entity you are interested in getting values from
    and then retrieve them and put the values into the fields on the Case form. Note: By establishing a Lookup field on a Dynamics 365 form a N:1 relationship
    is created. This N:1 (Case to Customer Asset) relationship can be used to retrieve Values from the 1 side of the relationship

    I was also helped by the information HERE which uses the Account
    and Contact entities.

    Hope this helps.



  • David Brooker Profile Picture
    66 on at
    RE: Updating fields in a Form interactively - Real Time Workflow, JavaScript, Action?

    Radu,

    You have confirmed what I thought I had read elsewhere which is that if I want the change to happen interactively on the screen, in front of the user then a "client / front-end" technology like JavaScript or Business Rules (which I think ultimately produces JavaScript?) is required. (I had better start refreshing my JavaScript and learning about Business Rules!)

    You have pointed me in the right direction.

    Thanks you

    David

  • Verified answer
    Radu Chiribelea Profile Picture
    6,667 on at
    RE: Updating fields in a Form interactively - Real Time Workflow, JavaScript, Action?

    Hi David,

    I suggest doing this through JavaScript or it might be worth checking if this can be achieved via Business Rules as well. This will be performed in real time and there is no need to call the refresh method.

    If you want to do it via the CRM Platform, then you need to refresh the form, as the client is unaware of what happens on the server in the background.

    Also, if you do this at a platform level, depending on what other business logic you have in place, this could trigger in the background several plug-ins workflows, etc - which will increase the time it takes for the server to send back the data to the client - impacting user experience.

    I guess each approach has it's pros and cons

    - if you want to do it simple then JS on the form - call the WEB API, as with build 9.X it has built in functions and makes it really easy to work with

    - if you want additional logic to be done in the background then use an Action or an Update Request and refresh the page after you get the response from the CRM Platform.

    "I am particularly keen to find out if a Real Time workflow can "interactively" update values on a Screen in front of a User. Would this require a screen refresh (F5) to be initiated? i.e. the Real Time work needs JavaScript to be involved to get the job done?"

    As i mentioned above, the form needs to be refreshed - the client is unaware of what happens on the server in the background. In order to start the workflow this requires a trigger (save, update, etc.) therefore you need to trigger this event via JavaScript or manually by saving the record.

    To trigger a workflow via JS you can have a look at this article: www.inogic.com/.../execute-workflow-using-web-api-in-dynamics-365-2. Still you need the response back from the CRM Platform before you can refresh the page to display the data.  

    Hope you find this useful,

    Radu

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
dkrishna Profile Picture

dkrishna 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans