UI action redirection to previous page issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2020 05:02 PM
we have a UI action Cancel Task on workorder table when clicked it should make the reason for cancellation field mandatory and visible and if entered then it should set the state to cancel, but when I click on the UI action it is redirecting to the previously worked (used page) , not sure how to debug this and it is also not updating the record.
Below is the UI policy to hide the field
UI action :
Script:
function checkReason() {
g_form.setDisplay("u_cancel_reason", true);
if (g_form.getValue('u_cancel_reason') == '') {
g_form.setMandatory("u_cancel_reason", true);
gs.addErrorMessage("a change task must be added before submitting the change");
//alert('Please enter the reason before cancellation');
return false;
}
gsftSubmit(null, g_form.getFormElement(), 'cancel'); // give the action name of your UI Action
}
if (typeof window == 'undefined')
serverResolve();
function serverResolve() {
new global.StateFlow().processFlow(current, 'ffc7a360d7230100fceaa6859e6103ae', 'manual');
//Moving redirect from state flow to UI action
action.setRedirectURL(current);
}
When clicked on the UI action , cancel reason will be mandatory and if selected , there is a OOB in UI action which will enforce worknotes mandatory ,
This is the OOB code
new global.StateFlow().processFlow(current, 'ffc7a360d7230100fceaa6859e6103ae', 'manual');
//Moving redirect from state flow to UI action
action.setRedirectURL(current);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2020 02:51 AM
There is no need for current.update() in the script of the UI Action because it is already present in the processFlow method of the StateFlow script include that gets called from the UI Action script.
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2020 02:49 PM
This is what happening when i click on Cancel UI action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2020 07:13 PM
function checkReason() {
g_form.setDisplay("u_cancel_reason", true);
if (g_form.getValue('u_cancel_reason') == '') {
g_form.setMandatory("u_cancel_reason", true);
gs.addErrorMessage("a change task must be added before submitting the change");
//alert('Please enter the reason before cancellation');
return false;
}
gsftSubmit(null, g_form.getFormElement(), 'cancel'); // give the action name of your UI Action
alert(1);
}
if (typeof window == 'undefined')
serverResolve();
function serverResolve() {
alert(2);
new global.StateFlow().processFlow(current, 'ffc7a360d7230100fceaa6859e6103ae', 'manual');
//Moving redirect from state flow to UI action
action.setRedirectURL(current);
}
when the work notes is not empty and when clicked on UI action I can see the alert 1 , when I comment out the alert1 and re run the same it is not showing the alert 2 , is there any issue with the code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2020 07:48 PM
This has to do with the fact that 2 phases of processing are mapped in the UI Action: a client-side phase (checkReason()) and a server-side phase (serverResolve()). You cannot see the output of alert(2) because it is processed on the server!!!
Please familiarize yourself with that concept of UI Actions, for example here: https://servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/
By the way:
You have not yet inserted the line of code I suggested in the function serverResolve()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2020 09:12 PM
Hi,
alert() won't work in server side so please remove that
seems something because of the processFlow() function
Can you try updating some other field and check
try this updated one and share the inputs
1) whether the short description got updated and redirected to current
function checkReason() {
g_form.setDisplay("u_cancel_reason", true);
if (g_form.getValue('u_cancel_reason') == '') {
g_form.setMandatory("u_cancel_reason", true);
gs.addErrorMessage("a change task must be added before submitting the change");
//alert('Please enter the reason before cancellation');
return false;
}
gsftSubmit(null, g_form.getFormElement(), 'cancel'); // give the action name of your UI Action
}
if (typeof window == 'undefined')
serverResolve();
function serverResolve() {
//new global.StateFlow().processFlow(current, 'ffc7a360d7230100fceaa6859e6103ae', 'manual');
//Moving redirect from state flow to UI action
current.short_description = 'testing';
current.update();
action.setRedirectURL(current);
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader