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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

UPDATE ENTITY USING ANOTHER ENTITY

(0) ShareShare
ReportReport
Posted on by

Hi;

I am trying to find ways how to update an entity when another entity has been updated in our CRM 2011 on premise.

I have a main form/entity called Collection Order form and under Collection Order form I can create another form which is called Job Order form. In the Job Order Form, I have a field named SDR Number which is automatically field up by a script when the Job Order Status has been change and saved. 

Now what I want is when the SDR Number has been generated in the Job Order Form, I want the same SDR Number to be copied to the same field under the Collection Order where the Job Order was created.

I already tried to this using workflow but unfortunately the SDR Number field under Collection Order is not appearing in the choices in fact I cannot choose any of the fields under collection order form when create the workflow under Job Order Form

Please advice thanks in advance.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Rajkumar Rajaraman Profile Picture
    on at

    You can use plugin. Refer this:

    unleashingcrm.wordpress.com/.../plugin-to-update-the-parent-entity-from-child-entity

    Hope this helps

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    Is there any relationship between Collection Order Form and Job Order Form?

    If you want to use a Workflow that must be established.

    If there is no relationship between the entities, the only way to implement this is using a plugin/action/custom workflow.

    The sample in the link above should provide you with a solution if you want to implement this using a Plugin.

    Hope this helps.

  • Community Member Profile Picture
    on at

    Hi Angel,

    Correct me if I'm wrong, so what I understand is that the Collection Order form has a lookup to the Job order and both forms have an SDR number.

    So if this is the case (there's no reference inside the Job Order to its Collection Order because the relation is N-1) .

    What you need to do is :

    1-A custom workflow activity with an input parameter to be the Job Order and its SDR number.

    2- In this custom workflow activity do some coding to retrieve the Collection Orders that reference this Job Order

    3- Update each of them

    4- Create a workflow that runs on the SDR number change for the Job Order entity

    P.S. you can do the same using plugins but I prefer the custom workflow activities for ease of logging and testing as I create it to run on demand in the beginning and keep running it during testing until it works :)

    Also if the SDR number is already on the Job Order form you can do some javascript to fetch it when you're referencing it on the Collection Order entity

  • Community Member Profile Picture
    on at

    I was able to make it work using workflow....

    But when I checked the workflows some of it failed.

    I check the work flow and found an error: Invalid Argument

    message: Incorrect attribute value type System.Int32

    Error Message:

    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Incorrect attribute value type System.Int32Detail:

    <OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance&quot; xmlns="schemas.microsoft.com/.../Contracts&quot;>

     <ErrorCode>-2147220989</ErrorCode>

     <ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic&quot; />

     <Message>Incorrect attribute value type System.Int32</Message>

     <Timestamp>2018-04-04T07:16:59.3462734Z</Timestamp>

     <InnerFault>

       <ErrorCode>-2147220989</ErrorCode>

       <ErrorDetails xmlns:d3p1="schemas.datacontract.org/.../System.Collections.Generic&quot; />

       <Message>Incorrect attribute value type System.Int32</Message>

       <Timestamp>2018-04-04T07:16:59.3462734Z</Timestamp>

       <InnerFault>

         <ErrorCode>-2147220970</ErrorCode>

         <ErrorDetails xmlns:d4p1="schemas.datacontract.org/.../System.Collections.Generic&quot; />

         <Message>System.ArgumentException: Incorrect attribute value type System.Int32

    Parameter name: msi_msiecsservicebranch</Message>

         <Timestamp>2018-04-04T07:16:59.3462734Z</Timestamp>

         <InnerFault i:nil="true" />

         <TraceText i:nil="true" />

       </InnerFault>

       <TraceText i:nil="true" />

     </InnerFault>

     <TraceText>[Microsoft.Xrm.Sdk.Workflow: Microsoft.Xrm.Sdk.Workflow.Activities.UpdateEntity]

    [UpdateStep5]

  • Community Member Profile Picture
    on at

    What is the type of this field on the form "msi_msiecsservicebranch"?

  • Community Member Profile Picture
    on at

    Option Set

  • Community Member Profile Picture
    on at

    Seems like you're trying to set it in the code as an int, instead you have to cast it first:

    e.g. :  yourObject["msi_msiecsservicebranch"]= new OptionSetValue(123);

    you have to cast it also if you're just using the attribute in your code

    e.g.: if ( (OptionSetValue)yourObject.Attributes["msi_msiecsservicebranch"] ==123)

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    Hi Angel,

    Seems like you are using a custom workflow activity. Are you passing the integer value as a parameter?

    If that is the case, then the answer is the same as what Omnia suggests.

    You need to assign the Optionset Value to the field, not the integer value.

    Basically:

    Entity myEntity = new Entity(entityName);

    myEntity["msi_msiecsservicebranch"] = new OptionSetValue(int32Value);

    Hope this helps.

  • Community Member Profile Picture
    on at

    Ok noted but, i am using workflow to update form1 using data from form2  and I not JS

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    That code is for Custom workflow, not JavaScript.

    Can you please share a screenshot or two how you are assigning the value to the Optionset field?

    Thanks.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans