<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Trigger UI action through rest api call in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/trigger-ui-action-through-rest-api-call/m-p/1930080#M587006</link>
    <description>&lt;P&gt;I believe your rest message is triggering the UI action, however it is using client side API's like g_form which cannot be triggered from server side REST, you would have to remove any client only side code and use server side, for example current.u_change_number instead of g_form.getValue('u_change_number') I believe.&lt;/P&gt;</description>
    <pubDate>Tue, 04 Feb 2020 23:40:03 GMT</pubDate>
    <dc:creator>Aleksas Kucins1</dc:creator>
    <dc:date>2020-02-04T23:40:03Z</dc:date>
    <item>
      <title>Trigger UI action through rest api call</title>
      <link>https://www.servicenow.com/community/developer-forum/trigger-ui-action-through-rest-api-call/m-p/1930073#M586999</link>
      <description>&lt;P class="ng-scope"&gt;Hello,&lt;/P&gt;
&lt;P class="ng-scope"&gt;I want to be able to trigger a UI action that is located on a record on a specific table&lt;/P&gt;
&lt;P class="ng-scope"&gt;I tried using this method found in this link:&amp;nbsp;&lt;A href="https://servicenowthink.wordpress.com/2019/10/15/call-any-ui-action-with-rest-api-or-ajax-ootb-updated/" rel="nofollow"&gt;https://servicenowthink.wordpress.com/2019/10/15/call-any-ui-action-with-rest-api-or-ajax-ootb-updated/&lt;/A&gt;&lt;/P&gt;
&lt;P class="ng-scope"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="ng-scope"&gt;This is in python:&lt;/P&gt;
&lt;P class="ng-scope"&gt;url = 'https://URLHERE/api/now/ui/ui_action/sys_id_of_ui_action?' \&lt;BR /&gt;'sysparm_table=table_of_target_record&amp;amp;' \&lt;BR /&gt;'sysparm_sys_id='&amp;nbsp;sys_id_of_target_record&amp;amp; '\&lt;/P&gt;
&lt;P class="ng-scope"&gt;'api=api'&lt;/P&gt;
&lt;P class="ng-scope"&gt;&lt;BR /&gt;headers = {"Content-Type":"application/json","Accept":"application/json"}&lt;BR /&gt;response = requests.post(url, auth=(user, pwd), headers=headers, verify = False )&lt;/P&gt;
&lt;P class="ng-scope"&gt;if response.status_code != 200 and response.status_code != 201:&lt;BR /&gt;print('Status:', response.status_code, 'Headers:', response.headers, 'Error Response:',response.json())&lt;BR /&gt;exit()&lt;/P&gt;
&lt;P class="ng-scope"&gt;data = response.json()&lt;/P&gt;
&lt;P class="ng-scope"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="ng-scope"&gt;and i am receiving&amp;nbsp;&lt;/P&gt;
&lt;DIV class="ng-scope"&gt;
&lt;DIV&gt;{&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;"error":&amp;nbsp;{&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;"message":&amp;nbsp;"A&amp;nbsp;JSONObject&amp;nbsp;text&amp;nbsp;must&amp;nbsp;begin&amp;nbsp;with&amp;nbsp;'{'&amp;nbsp;at&amp;nbsp;character&amp;nbsp;0&amp;nbsp;of&amp;nbsp;",&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;"detail":&amp;nbsp;"A&amp;nbsp;JSONObject&amp;nbsp;text&amp;nbsp;must&amp;nbsp;begin&amp;nbsp;with&amp;nbsp;'{'&amp;nbsp;at&amp;nbsp;character&amp;nbsp;0&amp;nbsp;of&amp;nbsp;"&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;},&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;"status":&amp;nbsp;"failure"&lt;/DIV&gt;
&lt;DIV&gt;}&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;is this even possible to perform?&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 04 Feb 2020 16:05:28 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/trigger-ui-action-through-rest-api-call/m-p/1930073#M586999</guid>
      <dc:creator>scocuzza</dc:creator>
      <dc:date>2020-02-04T16:05:28Z</dc:date>
    </item>
    <item>
      <title>Re: Trigger UI action through rest api call</title>
      <link>https://www.servicenow.com/community/developer-forum/trigger-ui-action-through-rest-api-call/m-p/1930074#M587000</link>
      <description>Try adding this to your body:

{
    "fields": [  { "name": ""  } ]
}</description>
      <pubDate>Tue, 04 Feb 2020 18:14:48 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/trigger-ui-action-through-rest-api-call/m-p/1930074#M587000</guid>
      <dc:creator>Aleksas Kucins1</dc:creator>
      <dc:date>2020-02-04T18:14:48Z</dc:date>
    </item>
    <item>
      <title>Re: Trigger UI action through rest api call</title>
      <link>https://www.servicenow.com/community/developer-forum/trigger-ui-action-through-rest-api-call/m-p/1930075#M587001</link>
      <description>&lt;P&gt;I received 201 created through postman but it actually didnt do anything when i checked the record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I manually pushed the ui action to check it there was anything stopping the ui action from going through but there was nothing&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="find_real_file.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/56386iE63DFBD467CF284C/image-size/large?v=v2&amp;amp;px=999" role="button" title="find_real_file.png" alt="find_real_file.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="find_real_file.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/56388i82578BBE5B984E12/image-size/large?v=v2&amp;amp;px=999" role="button" title="find_real_file.png" alt="find_real_file.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 18:34:57 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/trigger-ui-action-through-rest-api-call/m-p/1930075#M587001</guid>
      <dc:creator>scocuzza</dc:creator>
      <dc:date>2020-02-04T18:34:57Z</dc:date>
    </item>
    <item>
      <title>Re: Trigger UI action through rest api call</title>
      <link>https://www.servicenow.com/community/developer-forum/trigger-ui-action-through-rest-api-call/m-p/1930076#M587002</link>
      <description>Can you show the contents of UI action?</description>
      <pubDate>Tue, 04 Feb 2020 19:01:57 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/trigger-ui-action-through-rest-api-call/m-p/1930076#M587002</guid>
      <dc:creator>Aleksas Kucins1</dc:creator>
      <dc:date>2020-02-04T19:01:57Z</dc:date>
    </item>
    <item>
      <title>Re: Trigger UI action through rest api call</title>
      <link>https://www.servicenow.com/community/developer-forum/trigger-ui-action-through-rest-api-call/m-p/1930077#M587003</link>
      <description>&lt;P&gt;This is the XML of the UI action&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="find_real_file.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/56389i067BBA68EE7205A6/image-size/large?v=v2&amp;amp;px=999" role="button" title="find_real_file.png" alt="find_real_file.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 19:19:49 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/trigger-ui-action-through-rest-api-call/m-p/1930077#M587003</guid>
      <dc:creator>scocuzza</dc:creator>
      <dc:date>2020-02-04T19:19:49Z</dc:date>
    </item>
    <item>
      <title>Re: Trigger UI action through rest api call</title>
      <link>https://www.servicenow.com/community/developer-forum/trigger-ui-action-through-rest-api-call/m-p/1930078#M587004</link>
      <description>Can you also include the script?</description>
      <pubDate>Tue, 04 Feb 2020 19:41:15 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/trigger-ui-action-through-rest-api-call/m-p/1930078#M587004</guid>
      <dc:creator>Aleksas Kucins1</dc:creator>
      <dc:date>2020-02-04T19:41:15Z</dc:date>
    </item>
    <item>
      <title>Re: Trigger UI action through rest api call</title>
      <link>https://www.servicenow.com/community/developer-forum/trigger-ui-action-through-rest-api-call/m-p/1930079#M587005</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper"&gt;&lt;img src="https://www.servicenow.com/community/s/skins/images/22212D471CB7F3695D8701AAA52BFD91/responsive_peak/images/image_not_found.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper"&gt;&lt;img src="https://www.servicenow.com/community/s/skins/images/22212D471CB7F3695D8701AAA52BFD91/responsive_peak/images/image_not_found.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;function submitCAC() {
	//check if there are any empty mandatory fields
	var manField = false;
	var alertStr = '';
	var manArray = [];
	if(g_form.getValue('u_release_type') == 'Production' &amp;amp;&amp;amp; g_form.getValue('u_release_type_new') == '')
	{
		manArray = ['u_change_number','u_business_manager','u_project_leader','u_project_contact','u_application_support_required'];
		
		g_form.setMandatory('u_acceptance_tester', false);
	}
	else
	{
		manArray = ['u_acceptance_tester','u_business_manager','u_project_leader','u_project_contact','u_application_support_required'];
		g_form.setMandatory('u_change_number', false);
	}
	
	
	for(var i = 0;i&amp;lt;manArray.length;i++)
		{
		if(g_form.getValue(manArray[i]) == ''){
			g_form.setMandatory(manArray[i], true);
			alertStr += (g_form.getLabelOf(manArray[i]) + ', ');
			manField = true;
		}
	}
	alertStr = alertStr.replace(/,\s*$/, "");
	
	if (manField){
		alert('Please complete the following mandatory fields before submitting for Approval: '  + alertStr);
		return false;
	}
	
	if(!manField)
	{
	if (g_form.getValue('u_change_number') == '' &amp;amp;&amp;amp; g_form.getValue('u_enhancement_number') == '' &amp;amp;&amp;amp; g_form.getValue('u_request_number') == '')
		{
			alert('You must enter a Change Control #, Request # or Enhancement Number before submitting for approval.');
		return false;
		}
	}
	
	g_form.setValue('state', '3'); //"Approval"
	
	// Call the UI Action, and skip the "onclick" function.
	gsftSubmit(null, g_form.getFormElement(), 'submit_cac_for_approval');
}

//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if(typeof window == 'undefined')
	runUpdateCode();

//Server-side function
function runUpdateCode(){
	current.update();
	gs.addInfoMessage(current.number + ' submitted for Approval');
	action.setRedirectURL(current);
}&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Feb 2020 20:15:02 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/trigger-ui-action-through-rest-api-call/m-p/1930079#M587005</guid>
      <dc:creator>scocuzza</dc:creator>
      <dc:date>2020-02-04T20:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: Trigger UI action through rest api call</title>
      <link>https://www.servicenow.com/community/developer-forum/trigger-ui-action-through-rest-api-call/m-p/1930080#M587006</link>
      <description>&lt;P&gt;I believe your rest message is triggering the UI action, however it is using client side API's like g_form which cannot be triggered from server side REST, you would have to remove any client only side code and use server side, for example current.u_change_number instead of g_form.getValue('u_change_number') I believe.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 23:40:03 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/trigger-ui-action-through-rest-api-call/m-p/1930080#M587006</guid>
      <dc:creator>Aleksas Kucins1</dc:creator>
      <dc:date>2020-02-04T23:40:03Z</dc:date>
    </item>
  </channel>
</rss>

