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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Custom workflow to populate lookup field with text field

(0) ShareShare
ReportReport
Posted on by 270

Hi Guys

Please assist if you know how to work this out. I have two custom entities Entity A and Entity B. 

I have lookup  field on Entity A that lookup to Entity B. I also have text field on entity A that has the same values as the one in Entity B. I wan to write a custom workflow that will take the value from text field and pass it to lookup then lookup will return the record with that same value. I can do it manually by just copying the value from text and paste it on lookup then it will return the same value.

*This post is locked for comments

I have the same question (0)
  • RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: Custom workflow to populate lookup field with text field

    Hi Samrando,

    Did you create the custom workflow activity? If yes, are you facing any issues/ errors? If yes, then please share.

    If you haven't written the custom workflow then I would suggest you to go through the below sample and  write your own custom workflow activity.

    msdn.microsoft.com/.../gg334455(v=crm.7).aspx

  • Suggested answer
    Pawns or Kings Profile Picture
    on at
    RE: Custom workflow to populate lookup field with text field

    Hi Samrando,

    If I'm understanding the question correctly, it looks like you could just use Mapping. If it's a Parent/Child (1:N), which it sounds this way since you say Entity A looks up to Entity B, this seems to be the most efficient way.

    From the Solution, go to the parent entity (in this case, Entity B, since this is what the lookup is referencing) > 1:N relationships > Relationship (for example, in the Accounts 1:N relationships, there's incident_customer_accounts) > Mappings

    From the Mappings window, you can map which field from the source maps to the field of the child entity. You shouldn't have to write a custom workflow for this (although you can).

    Please let me know if this helps.

    David

  • Samrando Profile Picture
    270 on at
    RE: Custom workflow to populate lookup field with text field

    Hi Ravi here is my code

    CreditRisk is EntityA and Billing is EntityB

    new_billid is text  field in creditrisk

    new_billing is lookup field in creditrisk

    new_invoicenumber is text field in billing. it contains the value that i need to populate on new_billing.

    Entity CreditRisk = new Entity("new_creditRisk");

    //Entity billing = new Entity("new_billingdetail");

    if (CreditRisk.Attributes.Contains("new_billid"))

    {

    Entity CurrentbillID = service.Retrieve("new_billingdetail", ((EntityReference)CreditRisk["new_billing"]).Id, new ColumnSet("new_invoicenumber"));

    if (CurrentbillID.Attributes.Contains("kcd_invoicenumber"))

    {

    var billingName = CurrentbillID.Attributes["new_invoicenumber"].ToString();

    if (CreditRisk.Attributes["new_billid"].ToString() == billingName)

    {

    CreditRisk.Attributes["new_billing"] = new EntityReference("new_billingdetail",

                                                                                                   ((EntityReference)CreditRisk["new_billing"]).Id);

    }

    }

    service.Update(CreditRisk);

    }

  • Samrando Profile Picture
    270 on at
    RE: Custom workflow to populate lookup field with text field

    Hi Ravi here is my code

    CreditRisk is EntityA and Billing is EntityB

    new_billid is text  field in creditrisk

    new_billing is lookup field in creditrisk

    new_invoicenumber is text field in billing. it contains the value that i need to populate on new_billing.

    Entity CreditRisk = new Entity("new_creditRisk");

    //Entity billing = new Entity("new_billingdetail");

    if (CreditRisk.Attributes.Contains("new_billid"))

    {

    Entity CurrentbillID = service.Retrieve("new_billingdetail", ((EntityReference)CreditRisk["new_billing"]).Id, new ColumnSet("new_invoicenumber"));

    if (CurrentbillID.Attributes.Contains("kcd_invoicenumber"))

    {

    var billingName = CurrentbillID.Attributes["new_invoicenumber"].ToString();

    if (CreditRisk.Attributes["new_billid"].ToString() == billingName)

    {

    CreditRisk.Attributes["new_billing"] = new EntityReference("new_billingdetail",

                                                                                                   ((EntityReference)CreditRisk["new_billing"]).Id);

    }

    }

    service.Update(CreditRisk);

    }

  • Samrando Profile Picture
    270 on at
    RE: Custom workflow to populate lookup field with text field

    bill2.PNG what i have currently

    bill2.PNGwhat i want to achieve with custom workflow.

  • Samrando Profile Picture
    270 on at
    RE: Custom workflow to populate lookup field with text field

    Please take kcd_invoicenumber as new_invoicenumber

  • Samrando Profile Picture
    270 on at
    RE: Custom workflow to populate lookup field with text field

    Hi David will your solution populate my lookup?

  • RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: Custom workflow to populate lookup field with text field

    When do you want to rigger your custom code/ workflow. Are you looking for a workflow which your can run it on the existing records whic will populate the billing lookup based on the text value?

  • Samrando Profile Picture
    270 on at
    RE: Custom workflow to populate lookup field with text field

    I have two option field (yes/no) so on change of the field called Risk. (if risk=yes) then call the custom workflow

  • Pawns or Kings Profile Picture
    on at
    RE: Custom workflow to populate lookup field with text field

    Hi Samrando,

    Unfortunately not. I misunderstood the question. I thought you wanted a field from the parent (look up) record to populate into the child record.

    Regards,

    David

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans