UI Action - AJAX Call

rebecca75
Tera Contributor

I have this UI Action working, but I'm trying to understand the section below in BOLD that calls the Action Name. I dug that out from another script since my function launchWorkflow() wasn't firing in its place. I had to use the BOLD line to get it to work - but not sure why?

So the first function canSubmitRevision() is my onClick function, then that runs and goes to the Script include to run the server side script and returns the answer, then I code off that answer and if they canSubmit then finish the script with function launchWorkflow() or throw the alert and exit.

I just don't get what that BOLD line is doing exactly and the var isn't being called anywhere.

Can anyone explain so that I know next time?

Thanks!

R

function canSubmitRevision(){
 //var id = g_form.getUniqueValue();
 var doc = g_form.getValue('document');
 
 //AJAX call to determine if we can Submit this Revision
 var ga = new GlideAjax('CHETHManagedDocuments');
 ga.addParam('sysparm_name','canSubmit');
 //ga.addParam('sysparm_dr_sys_id', id);
 ga.addParam('sysparm_dr_doc', doc);
 ga.getXML(canSubmitCk);
}
 
function canSubmitCk(response) {
 var res = response.responseXML.documentElement.getAttribute("answer");
 if (res != 'cansubmit') {
  alert("The Data Centers Hosting This Service, RPO and RTO fields on the document form must be filled out to submit a revision.");
  return false;
 }
 var submit_result = gsftSubmit(null, g_form.getFormElement(), 'submit_revision');
}
 
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
 launchWorkflow();
 
function launchWorkflow(){
 current.stage="awaiting_review";
 current.update();
 action.setRedirectURL(current); 
}
1 ACCEPTED SOLUTION

Aishwarya Puri
Giga Expert

Hi,

As per my knowledge gsftSubmit() is used in UI Action, whenever we want to use both the client and server side in the same UI action we user this gsftSubmit() function. we can say that it work as as middle point between client and server script.

OR check this link to understand more

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

 

I hope it helped you, if it did please mark it correct or helpful.

Warm Regards, 

Aishwarya Puri

find_real_file.png

View solution in original post

4 REPLIES 4

rebecca75
Tera Contributor

I think I get it now - so the BOLD line is calling the Action Name of the UI Action so that the script runs from top to bottom, thus executing the remaining code and skipping the initial onClick function call. So it fires everything from //Code that runs without 'onclick' and down which executes the function launchWorkflow().

Correct or am I run? Just confused on the var submit_result that isn't called anywhere...

I think you've got it, when the button is clicked the client side onclick portion runs and then when the gsftSubmit() method is called it runs the server side part of the action that sets the stage and updates the record.

Aishwarya Puri
Giga Expert

Hi,

As per my knowledge gsftSubmit() is used in UI Action, whenever we want to use both the client and server side in the same UI action we user this gsftSubmit() function. we can say that it work as as middle point between client and server script.

OR check this link to understand more

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

 

I hope it helped you, if it did please mark it correct or helpful.

Warm Regards, 

Aishwarya Puri

find_real_file.png

Kalaiarasan Pus
Giga Sage

You can get the best explanation of this pattern here

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