CA Service Management

Expand all | Collapse all

Create button for change status

Legacy User

Legacy UserNov 26, 2015 02:38 AM

Giedrius Bekintis

Giedrius BekintisApr 25, 2016 08:27 AM

  • 1.  Create button for change status

    Posted Nov 25, 2015 10:33 PM

    Dear All,

     

    Can you help me.  I would like to create button status. Such as, Approve and request on request detail. I don't have knowledge about coding.

    When i click this button status will automatic change. Can you please help me investigate?

    approve button.png

     

    Thank you

    Chanopas



  • 2.  Re: Create button for change status

    Posted Nov 26, 2015 01:09 AM

    hi,

    here could be 2 ways:

    - popup Status Change window and then automaticaly save it with predefined status;

    - button click causes page refresh and it loads with new status; (this will contain Spel Macro)

    regards,

    cdtj



  • 3.  Re: Create button for change status

    Posted Nov 26, 2015 01:19 AM

    Dear cdtj,

     

    Can you give me more instruction to do this? Do you have any coding? Can you share your knowledge for me?

     

    Thank you

    Chanopas



  • 4.  Re: Create button for change status
    Best Answer

    Posted Nov 26, 2015 02:15 AM

    I just want to ask which method is prefered for you

    method 1:

    solution could be found here: Re: Add a Submit Button to Update Change Status

     

    method 2:

    method description could be found here: SPEL: Register custom webengine OP

    Please notice, followed code is built by me in 5 minutes from my other scripts and should work but didnt tested:

    op_custom.cfg:

    Z_CHG_STATUS z_chg_status MODIFY UPDATE
    

     

    detail_chg.htmpl:

        function switchStatus(status_code) {
            var url = cfgCgi +
            "?SID=" + cfgSID +
            "+FID=" + fid_generator() +
            "+OP=Z_CHG_STATUS" +
            "+FACTORY=chg" +
            "+PERSID=" + argPersistentID +
            "+POPUP_NAME=" + '$args.KEEP.POPUP_NAME' +
            "+ANALYST=" + '$cst.id' +
            "+NEWSTATUS=" + status_code;
            display_new_page(url, ahdframeset.workframe);
        }
        <PDM_MACRO name=button Caption="Approve" Func="switchStatus('<STATUS_CODE>')" hotkey_name="STATUS_APP[P]" ID=STATUS_APP>
        <PDM_MACRO name=button Caption="Reject" Func="switchStatus('<STATUS_CODE>')" hotkey_name="STATUS_REJ[J]" ID=STATUS_REJ>
    

     

    z_chg_status.spl

        z_chg_status(...) {
            int some_id; // You should pass the same value to next functions
            some_id = argv[0]; // here it is
            object new_obj; // Received object
            new_obj = argv[1];
            string return_msg;
            z_chg_status_call((string)new_obj.PERSID, (string)new_obj.NEWSTATUS, (uuid)new_obj.ANALYST);
            send_frame_resp((long)some_id, (object)new_obj, (string)"parent.ahdframe.location.reload();\n");
        }
        
        z_chg_status_call(string obj_id, string status_code, uuid analyst) {
            object zobj, gl;
            int msg_i;
    
    
            // Get DOB
            send_wait(0, top_object(), "call_attr", "chg", "dob_by_persid", 0, obj_id);
            zobj = msg[0];
    
    
            send_wait(0, top_object(), "get_co_group");
            if (msg_error()) {
                for (msg_i=0;msg_i<msg_length();msg_i++) {
                    logf(ERROR, "[%s] > msg[%d]: %s", persistent_id, msg_i, msg[msg_i]);
                    return;
                }
            }
            gl = msg[0];
            
            send_wait(0, zobj, "change_status", gl, analyst, "<STATUS_CHANGE_LOG_DESCRIPTION>", status_code, NULL);
            if (msg_error()) {
                for (msg_i=0;msg_i<msg_length();msg_i++) {
                    logf(ERROR, "[%s] > msg[%d]: %s", persistent_id, msg_i, msg[msg_i]);
                    return;
                }
            }
            
            send_wait(0, gl, "checkin");
            if (msg_error()) {
                for (msg_i=0;msg_i<msg_length();msg_i++) {
                    logf(ERROR, "[%s] > msg[%d]: %s", persistent_id, msg_i, msg[msg_i]);
                    return;
                }
            }
        }
    


  • 5.  Re: Create button for change status

    Posted Nov 26, 2015 02:38 AM

    tested method 2 in my env, worked fine for me.



  • 6.  Re: Create button for change status

    Posted Nov 26, 2015 02:47 AM

    Hi cdtj,

     

    I think i like method 1  because method 2 is hard code for me.

    On Method 1, I tried to use your code. I don't know where can i modified it to status Approve. When i click the button. Then i go to edit mode.

    I need to change status and save automaticly. Could you please help me? 

     

    Thank you

    Chanopas



  • 7.  Re: Create button for change status

    Posted Nov 26, 2015 03:12 AM

    On detail_chg find <body> tag and add saveOnLoad() to onload area,

    it will look like this:

    <BODY class="detailro" onUnload="unloadActions()" onload="loadActions();saveOnLoad();">

     

    to make this works you need to know status codes,

    for example to switch to Resolved, button should look like this (Where RE is code of Resolved status):

    <PDM_MACRO name=button Caption="Approve" Func="switchStatus('RE')" hotkey_name="STATUS_APP[P]" ID=STATUS_APP>



  • 8.  Re: Create button for change status

    Posted Nov 26, 2015 03:36 AM

    Hi cdtj,

     

    It still doesn't work. Could you please check my code?

    1.png2.png3.png

     

    Thank you

    CHanopas



  • 9.  Re: Create button for change status

    Posted Nov 26, 2015 04:00 AM

    there is syntax error,

    onload event didnt submit your function on page load.

    saveOnLoad; -> saveOnLoad();



  • 10.  Re: Create button for change status

    Posted Nov 26, 2015 04:11 AM
      |   view attached

    Hi cdtj,

     

    I already try it's not work. When i click button. It pop up edit mode. I will attach file to you.

    Please help me check.

     

    Thank you very much

    Chanopas

    Attachment(s)

    zip
    detail_cr.htmpl.zip   7 KB 1 version


  • 11.  Re: Create button for change status

    Posted Nov 26, 2015 04:25 AM
      |   view attached

    Modified your file,

    js is case sensetive, there was some conflicts.

    Also I forgot that new_status is passed within KEEP object.

    Give a try.

    Attachment(s)

    zip
    detail_cr.htmpl.zip   7 KB 1 version


  • 12.  Re: Create button for change status

    Posted Nov 26, 2015 04:38 AM

    Hi cdtj,

     

    We are appriciated for your help. and we would like to know you as i friend. This my email address is chanopas@entiis-th.com

    I'm in thailand. Thank you for support. Where do you change on my file? and I have another question. When i click approve status i would like to auto assign to assignee's group for example GroupA. How can i custom it?

     

    Thank you very much

    Chanopas



  • 13.  Re: Create button for change status

    Posted Nov 26, 2015 05:19 AM

    Your modified file is attached to my previous post :)

    Re: Create button for change status

     

    In case of autoassignment there is no way to avoid SPEL scripts.



  • 14.  Re: Create button for change status

    Posted Nov 26, 2015 04:02 AM

    Hi Cdtj,

     

    I try to do following your code in method 2. Nothing happen when i click Approve button and Reject button.

     

    Thank you

    Chanopas



  • 15.  Re: Create button for change status

    Posted Nov 26, 2015 04:27 AM

    method was for chg...

    try to replace:

    17: send_wait(0, top_object(), "call_attr", "chg", "dob_by_persid", 0, obj_id); 

    with

    17: send_wait(0, top_object(), "call_attr", "cr", "dob_by_persid", 0, obj_id); 



  • 16.  Re: Create button for change status

    Posted Dec 03, 2018 06:02 PM

    Method 2 is working for me.  We're using it to kick off the change control approval workflow in PAM.  However, there is one issue we're seeing.  When a change control is copied and the status is changed for the copied version (the button only works when the form is not in edit mode), we immediately get this error at the top of the form: AHD04423:ERROR: Another user has changed the record since it was first displayed.  The error in the log contains "web:local            2280 ERROR        freeaccess.spl       24538 Record has changed beneath us."  We've gone through the setup and can't locate the problem. Any ideas?



  • 17.  Re: Create button for change status

    Broadcom Employee
    Posted Apr 25, 2016 03:51 AM

    HI

    I want to change the status of workflow task

    any workaround is available for Tasks.

    Regards



  • 18.  Re: Create button for change status

    Posted Apr 25, 2016 08:27 AM

    You can use the same approach



  • 19.  Re: Create button for change status

    Broadcom Employee
    Posted Apr 26, 2016 02:19 AM

    Hi

    I done the below steps

    and getting below error.

    Any suggestion

    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Error

    04/25 22:10:29.85 testserver             domsrvr              5452 ERROR        dombase.c              493 Unknown message change_status received in wf:PDOB:PATTR:OB:MTH:

    04/25 22:10:29.85 testserver          web:local            5348 ERROR        z_chg_status.spl        33 [] > msg[0]: Unknown message

    04/25 22:10:34.09 testserver             domsrvr              5452 ERROR        dombase.c              493 Unknown message change_status received in wf:PDOB:PATTR:OB:MTH:

    04/25 22:10:34.09 testserver              web:local            5348 ERROR        z_chg_status.spl        33 [] > msg[0]: Unknown message

    04/25 22:10:36.88 testserver              domsrvr              5452 ERROR        dombase.c              493 Unknown message change_status received in wf:PDOB:PATTR:OB:MTH:

    04/25 22:10:36.88 testserver            web:local            5348 ERROR        z_chg_status.spl        33 [] > msg[0]: Unknown message

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    op_custom.cfg

    Z_CHG_STATUS z_chg_status MODIFY UPDATE

    ----------------------------------------------------------------------------------------------------

    z_chg_status.spl

    z_chg_status(...) { 
         int some_id; // You should pass the same value to next functions 
          some_id = argv[0]; // here it is 
           object new_obj; // Received object 
          new_obj = argv[1]; 
          string return_msg; 
         z_chg_status_call((string)new_obj.PERSID, (string)new_obj.NEWSTATUS, (uuid)new_obj.ANALYST); 
          send_frame_resp((long)some_id, (object)new_obj, (string)"parent.ahdframe.location.reload();\n"); 

       
    z_chg_status_call(string obj_id, string status_code, uuid analyst) { 
           object zobj, gl; 
          int msg_i; 


          // Get DOB 
           send_wait(0, top_object(), "call_attr", "wf", "dob_by_persid", 0, obj_id); 
          zobj = msg[0]; 


         send_wait(0, top_object(), "get_co_group"); 
           if (msg_error()) { 
               for (msg_i=0;msg_i<msg_length();msg_i++) { 
                   logf(ERROR, "[%s] > msg[%d]: %s", persistent_id, msg_i, msg[msg_i]); 
                   return; 
            } 
           } 
         gl = msg[0]; 
           
         send_wait(0, zobj, "change_status", gl, analyst, "<STATUS_CHANGE_LOG_DESCRIPTION>", status_code, NULL); 
          if (msg_error()) { 
             for (msg_i=0;msg_i<msg_length();msg_i++) { 
                 logf(ERROR, "[%s] > msg[%d]: %s", persistent_id, msg_i, msg[msg_i]); 
                  return; 
          } 

        
    send_wait(0, gl, "checkin"); 
    if (msg_error()) { 
    for (msg_i=0;msg_i<msg_length();msg_i++) { 
    logf(ERROR, "[%s] > msg[%d]: %s", persistent_id, msg_i, msg[msg_i]); 
    return; 


    ---------------------------------------------------------------------------------------------------------------

    detail_wf.htmpl

    <PDM_IF 0>
    detail_wf.htmpl
    WHEN PRESENTED:
        When we need to display a detail of a single Workflow Task
    INTENT:
        Display the detail info for the Workflow Task
    VARIABLES:
        string image The location of the image directory as specified in 
           in the config file.
        object  wf  args The Workflow Task object we are displaying.
                            See $NX_ROOT/bopcfg/majic/wf.maj for the
                            definition of attributes for 'OBJECT wf'
    </PDM_IF>
    <html lang="en"><head>
    <PDM_PRAGMA RELEASE=110>
    <PDM_INCLUDE FILE=styles.htmpl>
    <script type="text/javascript">
    var hdrTitle = "Change Workflow Detail";
    var hdrTitleUpd = "Update Change Workflow";
    var hdrTitleNew = "Create New Change Workflow";
    </script>
    <PDM_INCLUDE FILE=std_head.htmpl >
    <script>
    cfgDateFormat = "$date_format"
    </script>
    <script type="text/javascript" src="$CAisd/scripts/detail_form.js"></script>
    <script type="text/javascript" src="$CAisd/scripts/arrow_button.js"></script>
    <script type="text/javascript" src="$CAisd/scripts/check_submit.js"></script>
    <script type="text/javascript" src="$CAisd/scripts/img_link.js"></script>
    <script type="text/javascript" src="$CAisd/scripts/val_type.js"></script>
    <script type="text/javascript" src="$CAisd/scripts/sitemods.js"></script>
    <script type="text/javascript" src="$CAisd/scripts/attevts.js"></script>

    <script type="text/javascript">
    argPersistentID = "$args.persistent_id";

    function unloadActions()
    {
       if ( _dtl.edit )
          unload_check();
    }

    </script>
    </head>
    <body class="detailro" onunload="unloadActions()">
    </script>
    <PDM_INCLUDE FILE=std_body.htmpl filename="Change Workflow">
    <center>
    <script type="text/javascript">
    function switchStatus(status_code) { 
    var url = cfgCgi + 
    "?SID=" + cfgSID + 
    "+FID=" + fid_generator() + 
    "+OP=Z_CHG_STATUS" + 
    "+FACTORY=chg" + 
    "+PERSID=" + argPersistentID + 
    "+POPUP_NAME=" + '$args.KEEP.POPUP_NAME' + 
    "+ANALYST=" + '$cst.id' + 
    "+NEWSTATUS=" + status_code; 
    display_new_page(url, ahdframeset.workframe); 

    </script>

     


    <input type="hidden" name=FACTORY value=wf>
    <PDM_IF "$prop.form_name_3" == "edit">
    <input type="hidden" name=OP value="UPDATE">
    <PDM_IF 0 == $args.id>
    <span class="labeltext">You are not allowed to create a new Workflow</span>
    <PDM_ELSE>
    <PDM_IF $args.id>
    <input type="hidden" name=SET.id  value="$args.id">
    </PDM_IF>
    </PDM_IF>
    </PDM_IF>


    <script type="text/javascript">
    <PDM_MACRO name=dtlForm button=false factory=wf>
    <PDM_IF "$prop.form_name_3" == "edit">
    <PDM_MACRO name=btnStartRow>
    <PDM_MACRO name=button Caption="Save[s]" Func="detailSave()" hotkey_name="Save[s]" ID="btn001" Width=120>
    <PDM_MACRO name=button Caption="Cancel[n]" btnType="negative" Func="cancel_update('$prop.form_name_2','$args.id','$args.NEXT_PERSID')" hotkey_name="Cancel[n]" ID="btncncl" Width=120>
    <PDM_MACRO name=button Caption="Reset[r]" Func="pdm_reset()" hotkey_name="Reset[r]" ID="btn003" Width=120>
    <PDM_MACRO name=btnEndRow>
    </PDM_IF>
    </script>
    <PDM_IF "$prop.form_name_3" == "ro">
    <script type="text/javascript">
    <PDM_MACRO name=btnStartRow>
    </script>
    <PDM_IF $UserAuth \> 1>
    <PDM_FORM NAME="frmDTLRO">
    <input type="hidden" name=FACTORY value=wf>
    <input type="hidden" name=SET.id  value="$args.id">
    <input type="hidden" name=OP>
    <script type="text/javascript">
    if (allow_wf_edit()) {
    <PDM_MACRO name=button Caption="Edit[d]" Func="pdm_submit('frmDTLRO','UPDATE')" hotkey_name="Edit[d]" ID="btn001" Width=120>
    <PDM_MACRO name=button Caption="Approve" Func="switchStatus('COMP')" hotkey_name="STATUS_APP[P]" ID=STATUS_APP>
    <PDM_MACRO name=button Caption="Reject" Func="switchStatus('REJ')" hotkey_name="STATUS_REJ[J]" ID=STATUS_REJ>
    }
    </script>
    </PDM_FORM>
    </PDM_IF>
    <script type="text/javascript">
    <PDM_MACRO name=button Caption="Event History" Func="show_evt('wf', 'atev', $args.id)" hotkey_name="Event History" ID="SHOW_EVT_HISTORY" Width=0>
    <PDM_MACRO name=btnEndRow>
    </script>
    </PDM_IF>
    <script>
    <PDM_MACRO name=dtlStart>
    <PDM_MACRO name=dtlStartRow>
    <PDM_MACRO name=dtlReadonly hdr="Task" attr=task.sym>
    <PDM_MACRO name=dtlLookup hdr="Configuration Item" attr=asset>
    <PDM_MACRO name=dtlDate hdr="Actual Start Date" attr=start_date>
    <PDM_MACRO name=dtlStartRow>
    <PDM_MACRO name=dtlLookup hdr="Assignee" attr=assignee size=30>
    <PDM_MACRO name=dtlLookup hdr="Group" attr=group size=30>
    <PDM_MACRO name=dtlLookup hdr="Completed By" attr=done_by colspan=2>
    <PDM_MACRO name=dtlStartRow>
    <PDM_MACRO name=dtlTextbox hdr="Estimated Duration" attr=est_duration evt="onBlur='validate_duration_ts(this)'" size=30>
    <PDM_MACRO name=dtlTextbox hdr="Estimated Cost" attr=est_cost size=30>
    <PDM_MACRO name=dtlDate hdr="Estimated Completion Date" attr=est_completion_date>
    <PDM_MACRO name=dtlStartRow>
    <PDM_MACRO name=dtlTextbox hdr="Actual Duration" attr=actual_duration evt="onBlur='validate_duration_ts(this)'" size=30>
    <PDM_MACRO name=dtlTextbox hdr="Actual Cost" attr=cost size=30>
    <PDM_MACRO name=dtlDate hdr="Actual Completion Date" attr=completion_date>
    <PDM_IF "$prop.form_name_3" == "edit">
    <PDM_MACRO name=dtlStartRow>
    <PDM_MACRO name=dtlReadonly hdr="Sequence" attr=sequence>
    detailRowHdr("Status", 1 , "$args.REQUIRED_status");
    var item = '<PDM_SELECT NAME=SET.status ESC_STYLE=HTML FACTORY=tskstat WF_FAC_FOR_TSKSTAT=wf SELECTED="$args.status" SELECTED_SYM="$args.status.COMMON_NAME" TITLE="' + _dtl.lastHdrtext + '">';
    var ins_pos = item.indexOf("NAME=");
    if (ins_pos > 0)
    {
        _dtl.tabIndex++;
        item = item.substring(0, ins_pos) + " TABINDEX=" + _dtl.tabIndex + " " + item.substring(ins_pos, item.length);
    }
    detailSetRowData(item);
    <PDM_MACRO name=dtlLookupReadonly hdr="Change#" attr=chg>
    <PDM_ELSE>
    <PDM_MACRO name=dtlStartRow>
    <PDM_MACRO name=dtlLookupReadonly hdr="Service Type" attr=support_lev>
    <PDM_MACRO name=dtlLookupReadonly hdr="Change#" attr=chg>
    <PDM_MACRO name=dtlReadonly hdr="Category" attr=chg.category.sym colspan=2>
    <PDM_MACRO name=dtlStartRow>
    <PDM_MACRO name=dtlReadonly hdr="Sequence" attr=sequence colspan=2>
    <PDM_MACRO name=dtlReadonly hdr="Status" attr=status.sym colspan=2>
    </PDM_IF>
    <PDM_MACRO name=dtlStartRow>
    <PDM_MACRO name=dtlTextbox hdr="Task Description" attr=description colspan=4 keeplinks=yes rows=4 size=70 spellchk=yes>
    <PDM_MACRO name=dtlStartRow>
    <PDM_MACRO name=dtlTextbox hdr="Task Comments" attr=comments colspan=4 rows=4 size=70 spellchk=yes>
    <PDM_MACRO name=dtlEndTable>
    </script>

    <PDM_MACRO name=dtlEnd>
    <PDM_MACRO name=startNotebook hdr=wf_nb>
    <PDM_MACRO name=tab title="Service Type" file="xx_stype_tab.htmpl">
    <PDM_MACRO name=endNotebook>


    <PDM_INCLUDE FILE=std_footer.htmpl>
    </body>
    </html>
    <PDM_WSP>

    --------------------------------------------------------------------------------------

     

    Error

    04/25 22:10:29.85 testserver             domsrvr              5452 ERROR        dombase.c              493 Unknown message change_status received in wf:PDOB:PATTR:OB:MTH:

    04/25 22:10:29.85 testserver          web:local            5348 ERROR        z_chg_status.spl        33 [] > msg[0]: Unknown message

    04/25 22:10:34.09 testserver             domsrvr              5452 ERROR        dombase.c              493 Unknown message change_status received in wf:PDOB:PATTR:OB:MTH:

    04/25 22:10:34.09 testserver              web:local            5348 ERROR        z_chg_status.spl        33 [] > msg[0]: Unknown message

    04/25 22:10:36.88 testserver              domsrvr              5452 ERROR        dombase.c              493 Unknown message change_status received in wf:PDOB:PATTR:OB:MTH:

    04/25 22:10:36.88 testserver            web:local            5348 ERROR        z_chg_status.spl        33 [] > msg[0]: Unknown message

    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------



  • 20.  Re: Create button for change status

    Posted Apr 26, 2016 02:24 AM

    Hi,

    workflow object haven't status_change method, you can simply update object and define new status and comment (if needed),

    replace this part:

        send_wait(0, zobj, "change_status", gl, analyst, "<STATUS_CHANGE_LOG_DESCRIPTION>", status_code, NULL);  
          if (msg_error()) {  
            for (msg_i=0;msg_i<msg_length();msg_i++) {  
                logf(ERROR, "[%s] > msg[%d]: %s", persistent_id, msg_i, msg[msg_i]);  
                  return;  
          }  
    } 
    

     

     

    with:

     

    send_wait(0, zobj, "call_attr", "status", "set_val", "<NEW_STATUS_CODE>");
    send_wait(0, zobj, "call_attr", "comments", "set_val", "<OPTIONAL_COMMENT>");
    

     

    PS: you can debug webengine spel simply killing webengine (cmd: pdm_bounce webengine), no service recycling needed.

     

    Regards,

    cdtj



  • 21.  Re: Create button for change status

    Broadcom Employee
    Posted Apr 26, 2016 05:29 AM

    HI

    Thanks for your help but still its giving me the below error

     

    04/26 17:26:52.08 testserver          web:local            5428 ERROR        z_chg_status.spl        39 [] > msg[0]: Attempt to checkin with nothing checked out.

     

    regards



  • 22.  Re: Create button for change status

    Posted Apr 26, 2016 07:31 AM

    ah, checkout was part of status_change method.

    code will be:

    send_wait(0, gl, "checkout", zobj);
    send_wait(0, zobj, "call_attr", "status", "set_val", "<NEW_STATUS_CODE>"); 
    send_wait(0, zobj, "call_attr", "comments", "set_val", "<OPTIONAL_COMMENT>");
    


  • 23.  Re: Create button for change status

    Broadcom Employee
    Posted Apr 26, 2016 07:56 AM
      |   view attached

    Hi

    Thanks for your help

    find attached reference files for workflow status update.

    Regards

    Attachment(s)

    zip
    spel.zip   3 KB 1 version


  • 24.  Re: Create button for change status

    Broadcom Employee
    Posted Apr 26, 2016 07:56 AM
      |   view attached

    Hi

    Thanks for your help

    find attached reference files for workflow status update.

    Regards

    Attachment(s)

    zip
    spel.zip   3 KB 1 version