locked
How to fill in the Primary Field with the value from an Option Set RRS feed

  • Question

  • Hi, I want to copy the value of a option set into the primary field within the same entity.  I found this blog that indicates that this is possible using a workflow but I am unable to make this work.  Here is the link to the blog:  http://blogs.msdn.com/b/mvpawardprogram/archive/2012/02/27/microsoft-dynamics-crm-changing-the-primary-field-in-custom-entities.aspx

    Can anyone assist with my request or point me to a good workflow tutorial.

    Thanks

    Dave

    Friday, August 8, 2014 3:18 PM

Answers

  • Hi Davecihr,

    inside the update step you simply need to select first the field you want to update, and after the optionset. here a screenshot (it updates the "Job Title" (text field) of a contact with the Preferred Method of contact (optionset)


    My blog: www.crmanswers.net - Rockstar 365 Profile

    • Proposed as answer by Guido PreiteMVP Sunday, August 10, 2014 11:18 AM
    • Marked as answer by Davecihr Monday, August 11, 2014 7:36 PM
    Sunday, August 10, 2014 11:18 AM
  • You can accomplish the task with a little bit of Javascript.  Unless you intend to change the data from another workflow or a web service,  using a script should be your first choice.

    The following snippet binds to the form OnSave event and assign the optionset value to the name field.

    var Name, OptionSet1, 
        xrmPage = Xrm.Page;
    
    //form load calls this function
    function OnCrmPageLoad() {
        //create attributes
        Name = xrmPage.getAttribute("new_name");
        OptionSet1 = xrmPage.getAttribute("new_optionset1");
        //bind onsave
        xrmPage.data.entity.addOnSave(OnCrmPageSave)
    }
    
    function OnCrmPageSave(eContext) {
        //put optionset text in name value
        Name.setValue(OptionSet1.getText())
        //ensure submit
        Name.setSubmitMode("always");
    }
     

    If you haven’t done it by now, here is how to add a js resource to your form.

    It’s demoed on 2011 but it’s the same for 2013.

    https://www.youtube.com/watch?v=Ztha5urjKQg

    The relevant part of the demo starts at 3:30 and end on 6:55.

    Cheers


    Dev Blog: Dynamics CRM - Thinking outside the Box


    • Edited by Adi Katz Sunday, August 10, 2014 7:29 PM
    • Marked as answer by Davecihr Monday, August 11, 2014 7:36 PM
    Sunday, August 10, 2014 6:01 PM

All replies

  • Hi Davecihr,

    the tutorial you linked is pretty straightforward, at which part you found problems?


    My blog: www.crmanswers.net - Rockstar 365 Profile

    Friday, August 8, 2014 5:04 PM
  • I am new to CRM, and I am having difficulty creating the actual workflow. The blog simply says created workflow to copy data, well I do not know how to create a workflow. Specifically I think the "Steps"

    I have created a progress category "Workflow", set the entity and start when record is created or option set field is changed.  Then added a "update record step" to update my selected entity and now I am stuck with the "set properties" button.  I have know idea how to use the form assistance screen and how to proceed with defining that I want to copy the text (not value) of my option set into the primary field.

    I have not been able to find any tutorial or demo of creating workflow process that can assist me.

    I also wonder if a plug-in is better option instead of a workflow for this kind of "update".

    I am just starting with crm and using crm 2013.

    Thanks

    Dave

     


    • Edited by Davecihr Friday, August 8, 2014 7:54 PM
    Friday, August 8, 2014 7:51 PM
  • Hi Davecihr,

    inside the update step you simply need to select first the field you want to update, and after the optionset. here a screenshot (it updates the "Job Title" (text field) of a contact with the Preferred Method of contact (optionset)


    My blog: www.crmanswers.net - Rockstar 365 Profile

    • Proposed as answer by Guido PreiteMVP Sunday, August 10, 2014 11:18 AM
    • Marked as answer by Davecihr Monday, August 11, 2014 7:36 PM
    Sunday, August 10, 2014 11:18 AM
  • You can accomplish the task with a little bit of Javascript.  Unless you intend to change the data from another workflow or a web service,  using a script should be your first choice.

    The following snippet binds to the form OnSave event and assign the optionset value to the name field.

    var Name, OptionSet1, 
        xrmPage = Xrm.Page;
    
    //form load calls this function
    function OnCrmPageLoad() {
        //create attributes
        Name = xrmPage.getAttribute("new_name");
        OptionSet1 = xrmPage.getAttribute("new_optionset1");
        //bind onsave
        xrmPage.data.entity.addOnSave(OnCrmPageSave)
    }
    
    function OnCrmPageSave(eContext) {
        //put optionset text in name value
        Name.setValue(OptionSet1.getText())
        //ensure submit
        Name.setSubmitMode("always");
    }
     

    If you haven’t done it by now, here is how to add a js resource to your form.

    It’s demoed on 2011 but it’s the same for 2013.

    https://www.youtube.com/watch?v=Ztha5urjKQg

    The relevant part of the demo starts at 3:30 and end on 6:55.

    Cheers


    Dev Blog: Dynamics CRM - Thinking outside the Box


    • Edited by Adi Katz Sunday, August 10, 2014 7:29 PM
    • Marked as answer by Davecihr Monday, August 11, 2014 7:36 PM
    Sunday, August 10, 2014 6:01 PM
  • Thank you Adi and Guido, both worked.  I think I will go with the javascript approach.

    Dave

    Monday, August 11, 2014 7:36 PM