locked
how to change business process on field event change in CRM 2013 RRS feed

  • Question

  • Hi,

    I have created a custom business process named "Outsource Process" and its guid "'EBF0B23F-1E4B-41A2-B8BC-9568353FC8E0". I want to change Process on field change event. I have created a script for changing process. Its working but when I create a new record and field change then new page display and record is not saved. When I open any record and change the field, process is updated but new record page display.

    function onSelectedValueChange(){
     var optionValue = Xrm.Page.getAttribute("new_service").getValue();
    if(optionValue == 5)
    {

       Xrm.Page.getAttribute('processid').setValue('EBF0B23F-1E4B-41A2-B8BC-9568353FC8E0');
     //  Xrm.Page.getAttribute("staged").setSubmitMode(“always”);
       Xrm.Page.getAttribute('stageid').setValue('872995C2-4493-45D7-A7A6-A4A455545496');
    Xrm.Page.data.entity.save();
    //Xrm.Page.data.refresh()
    window.location.reload(true);
       }
    }

    Thursday, January 1, 2015 5:25 AM

All replies

  • If processID is a lookup field you need to create an object array like below:

    var processID = new Array();
          processID[0] = new Object();
          processID[0].id ='EBF0B23F-1E4B-41A2-B8BC-9568353FC8E0';
          processID[0].name = processID;
          processID[0].entityType = "processID";
          
          Xrm.Page.getAttribute("processID").setValue(processID);

    • Proposed as answer by Kristian Cole Thursday, February 16, 2017 1:04 PM
    Thursday, February 16, 2017 9:55 AM
  • I think, Business Process will be applied only when Record is created, in your case you are expecting Process change even when record is not yet created.

    Code in you JS; window.location.reload(true), will reload the entire form and since no data is saved yet you see empty new record form.

    I would suggest to put a FormType (Xrm.Page.ui.getFormType()) and apply the change event only for existing record.


    MaKeer

    Thursday, February 16, 2017 7:06 PM