Calling Glide Ajax in Ui Action, not working

Vdix
Tera Guru
if(current.close_notes.nil()){
	gs.addErrorMessage(gs.getMessage("Please specify a resolution note."));
	action.setRedirectURL(current);
	current.setAbortAction(true);
}
// else if(current.u_resolution_type.nil()){
// 	gs.addErrorMessage(gs.getMessage("Please specify a resolution type."));
// 	action.setRedirectURL(current);
// 	current.setAbortAction(true);
// }
else if(current.resolution_code.nil()){
	gs.addErrorMessage(gs.getMessage("Please specify a resolution code."));
	action.setRedirectURL(current);
	current.setAbortAction(true);
}
else{	
	if (current.contact_type == 'hg_analytics'){
		current.u_alert_investigation = current.u_alert_investigation_pre_qc;
	}
	
	if(current.resolution_code == 9){
		setCaseLog(current.number, current.state, current.u_substate, 6, 6, current.contact_type);
		current.u_substate = 6;
	}else{
		setCaseLog(current.number, current.state, current.u_substate, 6, 7, current.contact_type);
	}
	
	current.resolved_by = gs.getUserID();
	current.state = 6;
	current.u_resolve_timestamp = new GlideDateTime();
	current.resolved_at = new GlideDateTime();
	current.update();
	action.setRedirectURL(current);
}

function Resolve(){
var dte = g_form.getValue('u_work_in_progress_time');
        var ga = new GlideAjax('CalculateDiff');
		ga.addParam('sysparm_name', 'getDurationFromNow');
        ga.addParam('sysparm_sdate', dte);
        ga.getXMLWait();

        var answer = ga.getAnswer(); //getAnswer() retrieves the result for you
        var usrResponse = confirm('Are you sure you have spent duration: ' + answer);
        if (usrResponse == true) {
            //DO nothing

        } else {
            return false;
        }
    }

function setCaseLog(number, from_state, from_substate, to_state, to_substate, stream){
	var cslog_gr = new GlideRecord('sn_customerservice_cases_log');
	cslog_gr.initialize();
	cslog_gr.u_case = number;
	cslog_gr.u_from_state = from_state;
	cslog_gr.u_from_substate = from_substate;
	cslog_gr.u_to_state = to_state;
	cslog_gr.u_to_substate = to_substate;
	cslog_gr.u_stream = stream;
	cslog_gr.insert();	
}

On Click - Resolve()

 

Ui Action - is in scope application,

Script include is in global domain,

 

1 ACCEPTED SOLUTION

Anil Lande
Kilo Patron

Hi Vibha,

1. As you mentioned the UI Action is in scope application and you are calling global script include. Make sure your script include is accessible in other scopes (value on form should be All Application scope).

find_real_file.png 

2. When you call script include from different scope you need to use API Name, instead of Name. e.g. var ga = new GlideAjax('global.getAlertURL ');

3. IF your UI action is performing both server and Client side operation then make sure to call UI Action Name uisng gsftSubmit(); 

check below links to know more about gsftSubmit and uses:

https://community.servicenow.com/community?id=community_question&sys_id=49439709db006c1011762183ca96...

https://servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/

 

After doing above changes, make sure to put logs to see where your code stopped working.

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

4 REPLIES 4

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Can you share what debugging you did? Up to which point the UI Action is working? Where the UI Action is failing?

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Thanks Mark.. when I am clicking on resolve button , it’s doing nothing. after adding the script include part the resolved button stop working.

Maik Skoddow
Tera Patron
Tera Patron

Hi @vibha 

please read carefully the following article. It explains how to write the script in the correct way so that your code is working both server-side and client-side.

At the moment, you are mixing server-side and client-side code, which leads to the described non-working state.

https://servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/

Kind regards
Maik

If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.

Anil Lande
Kilo Patron

Hi Vibha,

1. As you mentioned the UI Action is in scope application and you are calling global script include. Make sure your script include is accessible in other scopes (value on form should be All Application scope).

find_real_file.png 

2. When you call script include from different scope you need to use API Name, instead of Name. e.g. var ga = new GlideAjax('global.getAlertURL ');

3. IF your UI action is performing both server and Client side operation then make sure to call UI Action Name uisng gsftSubmit(); 

check below links to know more about gsftSubmit and uses:

https://community.servicenow.com/community?id=community_question&sys_id=49439709db006c1011762183ca96...

https://servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/

 

After doing above changes, make sure to put logs to see where your code stopped working.

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande