Sage CRM Opportunity Custom Content - Get current workflow ID

I'm preparing to migrate our opportunity workflow to a new one, and need to include a bit of javascript in the screens custom content to hide/show some fields based on the workflow the opportunity is following. 

I have no issue with the hide/show part, but I'm not sure how/if I can get the ID of the workflow it is following. 

Can anyone advise if this is possible?

  • 0

    Josh:  It has been a while since I have done this.  However, I believe you can get to which workflow is being used through the URL.  If not, I can check some notes.

    This article might help explain things....

    https://www.sagecity.com/sage-global-solutions/sage-crm/b/sage-crm-hints-tips-and-tricks/posts/distinguishing-between-primary-workflow-rules-in-create-scripts

    Hope this helps.  :-)

  • 0 in reply to Michele Gaw

    Thanks Michele - While very interesting unfortunately this won't help me in this situation. This only gives the current rule ID rather than the workflow ID, and it is also quite inconsistent when it includes that in the URL. For example if opening the opportunity from the recent menu it doesn't include any of the 'key' values in the URL. 

  • 0 in reply to joshSWR

    Josh:  I will take a look at my notes and see if I can offer more.  Also, if you have the current rule id, you can use that to find your way back to the workflow id.

    I will follow up with what I find.

  • 0 in reply to Michele Gaw

    When you initially start a workflow, there are fields that you can be setup to autopopulate the field.  Like oppo_type.  Since I don't know the different types, I will refer to New or Old.

    When the initial oppo screen is displayed the oppo type field will contain either New or Old.  You can then use this type to display a field or not using the Values() Colletion.  

    At one time, there was an article in the community titled "Display certain fields depending on workflow".  

    However, I can no longer find the article.  Hope this helps!

  • 0 in reply to Michele Gaw

    The Workflow ID is basically (in SQL) done as Opportunity (e.g. Oppo_Workflowid) > WorkflowInstance (wkin_instanceid) From WorkflowInstance table you're looking for Wkin_workflowid for the Workflow ID number. 

    Though personally it would be better to have the 'New Opportunity' buttons for both workflows flag the Opportunity in some way if it is A or B then in future you just need to query the opportunity record itself to know which workflow it is following. 

  • 0

    Hi

    You can try this. (it’s a bit tricky)

    Add the script below in the create script box of any field of the opportunity summary screen.

    It will add on your screen a variable with the Id of the workflow, which can be checked by any client side JavaScript, so you can hide fields using Client Side API. This can be adapted also to be used in server side scripting.

     

    var Oppoid = CRM.GetContextInfo('Opportunity', 'oppo_opportunityId');   //get current opportunity in context
    var WfId = '0';                                                                                             //assure always have a value
    if (Oppoid != 'undefined' && Oppoid != '' && Oppoid != 0){                     //check if we have Id. (When creating opportunity we have no Id)
           sql = "select WkIn_WorkflowId from vWorkflowInstance where WkIn_CurrentEntityId = 10 and WkIn_CurrentRecordId = "+ Oppoid;  //query for gettin the current wfid value
           Query= CRM.CreateQueryObj(sql)
           Query.SelectSql();
           if (!Query.eof)
                 WfId = Query("WkIn_WorkflowId");
    CRM.AddContent('<scr'+'ipt>var WfId="'+WfId+'";</scr'+'ipt>');    //add a varibale in your page wich can be checked with JavaScript Custom Side.
     

     

    Best regards