How to trigger a workflow through UI page

maheshch18
Tera Contributor

Hi Team,

 

We have "Reschedule Change" button on the change form.

 

maheshch18_0-1716984527202.png

 once user fill the details and click the "yes" button need to trigger the workflow.

 

I have written code but its not working.

 

HTML:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:ui_form>
    <input type="hidden" name="selection_result" id="selection_result" value=""/>
    <input type="hidden" name="my_sys_id" id="my_sys_id" value="${RP.getWindowProperties().get('sys_id')}"/>
    <div style="text-align:left;">          
        ${gs.getMessage('Are you sure want to rescheduled the change request:')} <br/><br/>
   
        <!-- <table>
            <tr>
                <td>Revised Start Date:</td><n/>
                <td><input type="date" id="date_id" name="start date" /><n/></td>
                </tr>
                </br>
                <tr>
                <td>Revised End Date:</td><n/>
                <td><input type="date" id="date_id" name="end date"/></td>
                </tr>
        </table> -->
        <div class="row">
        <div><span style="padding:10px;font-weight;"> Revised Start Date: </span><n/>
        <input type="date" id="date_id" name="start date" />
        </div>
        </div>
        <div class="row">
        <div><span style="padding:10px;font-weight;"> Resived End Date: </span><n/>
        <input type="date" id="date_id" name="end date" />
        </div>
        </div>
        <br/>
        <div class="row">
        <div >
            <span style="padding:16px;font-weight;">Reason for reschedule change request:</span>
        </div>
    </div>
    <div class="row">
        <div class="form-horizontal">
            <div class="form-group" style="margin-left:16px !important;margin-right:16px !important">
                <textarea id="comments" name="comments" class="form-control" spellcheck="true" style="overflow: hidden; word-wrap: break-word; resize: none;" required="required"></textarea>
   </div>
    </div>
    </div>
    <div align="right">
        <g:dialog_buttons_ok_cancel ok_text="${gs.getMessage('Yes')}" ok_title="${gs.getMessage('Yes')}" ok="return actionOK();" cancel_text="${gs.getMessage('No')}" cancel_title="${gs.getMessage('No')}" cancel="return cancel();"/>
      </div>
    </div>
</g:ui_form>
</j:jelly>
 
Client Script:
function cancel() {
    GlideDialogWindow.get().destroy();
    return false;
}


function actionOk() {
    // gel() is equivalent to getElementbyID("element")
    // In this case it sets value of hidden input field "yes_no_result"
    var c = gel('yes_no_result');
    c.value = 'yes';
    return true;
}
 
Process Script: 
var workflowId;
workflow = new Workflow();
workflowId = workflow.getWorkflowFromName('Reschedule Change ');
workflow.startFlow(workflowId, current, 'Reschedule Change ', null);
 
Please check and provide the solution.
 
Regards,
Mahesh.
2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@maheshch18 

is it going inside the processing script

if yes then current object won't work in processing script

you need to pass the record sysId, GlideRecord it and then use that object

var recordSysId = my_sys_id;

var gr = new GlideRecord("change_request");
gr.addQuery("sys_id", recordSysId);
gr.query();
if (gr.next()) {
    var workflowId;
    workflow = new Workflow();
    workflowId = workflow.getWorkflowFromName('Reschedule Change ');
    workflow.startFlow(workflowId, gr, 'Reschedule Change ', null);

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

 

Thanks for the quick response.

 

Once i have filled the details after click the yes button.

 

It returns to the below page:

 

maheshch18_0-1716990048918.png

I want to update set the values in the change form.

 

Please provide the solution.

 

Regards,

Mahesh