UI Action Send for Approval

Avinash Dubey2
Tera Contributor

I want to create an Ui Action :

Send for approval

  • This will be visible when status is draft and record is not new.
  • After clicking on this button status changes to pending for approval and assignment group must be filled with "service desk" and an approval will be sent to "service desk" group. Once approval is approved status should be Work in progress.

I have written the following code :But the assignment group is not saving to when service desk is configured from this code.I dont know how to implement "an approval will be sent to "service desk" group".

function SendforApproval() {

    if (g_form.getValue('u_status') == '2'); {
        g_form.setValue('u_status', '4');
        g_form.setValue('assignment_group', 'Service Desk');
        g_form.update();
        gsftSubmit(null, g_form.getFormElement(), 'SendforApproval');

    }
}
if (typeof window == 'undefined')
    serverResolve();

function serverResolve() {
    current.incident_state = IncidentState.RESOLVED;
    current.state = IncidentState.RESOLVED;
    current.resolved_by = gs.getUserID();
    current.update();
}

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

update everything in server side since you are anyhow updating it in server function

function SendforApproval() {

	if (g_form.getValue('u_status') == '2') 
		gsftSubmit(null, g_form.getFormElement(), 'SendforApproval');
}

if (typeof window == 'undefined')
	serverResolve();

function serverResolve() {

	current.setValue('u_status', '4');
	current.setDisplayValue('assignment_group', 'Service Desk');

	current.incident_state = IncidentState.RESOLVED;
	current.state = IncidentState.RESOLVED;
	current.resolved_by = gs.getUserID();
	current.update();
}

regards
Ankur

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

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

update everything in server side since you are anyhow updating it in server function

function SendforApproval() {

	if (g_form.getValue('u_status') == '2') 
		gsftSubmit(null, g_form.getFormElement(), 'SendforApproval');
}

if (typeof window == 'undefined')
	serverResolve();

function serverResolve() {

	current.setValue('u_status', '4');
	current.setDisplayValue('assignment_group', 'Service Desk');

	current.incident_state = IncidentState.RESOLVED;
	current.state = IncidentState.RESOLVED;
	current.resolved_by = gs.getUserID();
	current.update();
}

regards
Ankur

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

Hi ,

After updating the UI Action .I am getting error :Error Message

Unable to find UI Action with name 'SendforApproval' on table 'u_custometable'
 
I have checked the UI action but was not able to find the issue 

Hi,

your action name field on UI action is empty

update it with SendforApproval

also update script as this

function SendforApproval() {

	if (g_form.getValue('u_status').toString() == '2') 
		gsftSubmit(null, g_form.getFormElement(), 'SendforApproval');
	else
		return false;
}

if (typeof window == 'undefined')
	serverResolve();

function serverResolve() {

	current.setValue('u_status', '4');
	current.setDisplayValue('assignment_group', 'Service Desk');

	current.incident_state = IncidentState.RESOLVED;
	current.state = IncidentState.RESOLVED;
	current.resolved_by = gs.getUserID();
	current.update();
}

Regards
Ankur

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

@Avinash Dubey 

I already answered your question and it's just that you didn't mention action name in your UI action. I considered it must be there since you are using gsftSubmit.

If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.

Regards
Ankur

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