Overriding a global UI action and getting Action Not Authorized

patrick vader
Kilo Contributor

I'm overriding a global UI action for 'New' for related lists on the project task table to ask for confirmation before creating a new project task on a project task.  I changed the code for now to just stop the user from doing so if the parent project task is closed. 

I referenced ServiceNowGuru site that most of the posts of this nature reference first.  I added the client "onclick" code, changed the action name and it doesn't go to a new form - it goes to the previous list - and I'm getting the 'Action Not Authorized' error.  I've looked at posts on this issue but I can't get them to apply to my case.  Any help is appreciated.

find_real_file.png
Here is my code:

function runClientCode() {
   var savedState = g_scratchpad.ProjectTaskState;
   var userAnswer;

   if ((savedState == '3') || (savedState == '4')) {
      g_form.addErrorMessage(getMessage('The Project Task is currently closed. Please re-open before adding new child Project Tasks'));
      return false;
   }
   else {
      // MUST call the 'Action name' set in this UI Action
      gsftSubmit(null, g_form.getFormElement(), 'sysverb_new_project_task');
   }
}

// Code that runs without 'onclick'
// Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
   runServerCode();


function runServerCode() {
   var uri = action.getGlideURI();
   var path = uri.getFileFromPath() + '';

   path = path.substring(0, path.length - 5) + '.do';
   uri.set('sys_id', '-1');
   path = checkWizard(uri, path);

   if (path)
      action.setRedirectURL(uri.toString(path));

   action.setNoPop(true);
}

function checkWizard(uri, path) {
   var already = uri.get('WIZARD:action');
   if (already == 'follow')
      return null;

   var wizID = new GlideappWizardIntercept(path).get();
   if (!wizID)
      return path;

   uri.set('sysparm_parent', wizID);
   uri.deleteParmameter('sysparm_referring_url');
   uri.deleteMatchingParameter('sysparm_list_');
   uri.deleteMatchingParameter('sysparm_record_');
   uri.deleteParmameter('sys_is_list');
   uri.deleteParmameter('sys_is_related_list');
   uri.deleteParmameter('sys_submitted');
   uri.deleteParmameter('sysparm_checked_items');
   uri.deleteParmameter('sysparm_ref_list_query');
   uri.deleteParmameter('sysparm_current_row');

   uri.set('sysparm_referring_url', uri.toString());
   uri.deleteMatchingParameter('fancy.');
   uri.deleteMatchingParameter('sys_rownum');
   uri.deleteMatchingParameter('sysparm_encoded');
   uri.deleteMatchingParameter('sysparm_query_encoded');
   uri.deleteParmameter('sysparm_refer');

   return 'wizard_view.do';
}

 

3 REPLIES 3

Prateek kumar
Mega Sage

May be this could help:

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


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Thanks for your reply.  Yeah I saw that one.  I had already changed it from the global UI Action, and after seeing this, I changed it again to a shorter length action.  No change.  This is frustrating.

Hello,

 

Did you manage to solve it? I have the same issue now.

 

Thanks,

Elena