How to make suspend reasons mandatory on click of suspend button?

ankitkathuria
Tera Contributor

Requirement: For parent work order, suspended reasons field (sla_suspended_reason) should be mandatory at the time of clicking suspend button.

 

UI Action Script:

 

if (current.work_notes != '') {
    new StateFlow().processFlow(current, '7e82e738d7230100fceaa6859e61037d', 'manual');
} else {
    //current.setMandatory('sla_suspended_reason', true);
    gs.addErrorMessage(gs.getMessage('Provide a reason for suspension in Work notes'));
}
8 REPLIES 8

@ankitkathuria 

Here are the steps

1) Make the UI action as client + server

2) in UI action check if comments is mandatory

3) inside the server side code use the code already given OOB

4) in workspace client script use GlideAjax and use the state model logic

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

@ankitkathuria 

something like this

AnkurBawiskar_0-1738587413131.png

 

 

function showSuspend() {
    if (g_form.getValue('comments') == '') {
        g_form.setMandatory('comments', true);
        g_form.addErrorMessage("comments are mandatory");
        return false;
    }
    gsftSubmit(null, g_form.getFormElement(), "work_order_suspend");
}

if (typeof window == 'undefined')
    runServerCode(); //Server-side function

function runServerCode() {
    if (current.work_notes != '') {
        new StateFlow().processFlow(current, '7e82e738d7230100fceaa6859e61037d', 'manual');
    }
}

 

Workspace client script

 

function onClick(g_form) {
    if (g_form.getValue('comments') == '') {
        g_form.setMandatory('comments', true);
        g_form.addErrorMessage("comments are mandatory");
        return false;
    }
	else{
		// send sysid of record
		var sysId = g_form.getUniqueValue();
		// use GlideAjax and send this and query and use this line in server side code
                 // instead of current give that gliderecord object which you used to query the wm_order table with the sysId
		//  new StateFlow().processFlow(gr, '7e82e738d7230100fceaa6859e61037d', 'manual');
	}
}

 

AnkurBawiskar_1-1738587532420.png

 

I hope I answered almost every detail of your question and you can take it from here based on developer skills.

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

@ankitkathuria 

Hope you are doing good.

Did my reply answer your question?

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

@ankitkathuria 

Thank you for marking my response as helpful.

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