UI Action not working as expected in Agent workspace

ramwons
Kilo Expert

I have an UI action "Create Incident" in RITM table. A pop up opens which prompts the user to enter comment. It creates an Incident once the user enter the comments and click OK. The Incident gets associated with the RITM. This is working as expected. Thanks to @Ankur Bawiskar 

But the same functionality is not working in our Agent workspace. The pop up opens fine. The Incident is also getting created successfully. But the Incident is not getting associated with the RITM.

 

Here is the UI Action script

Script:

function createIncident() {
	var number = g_form.getValue("number");
	var sysId = g_form.getUniqueValue();
	var gDialog = new GlideDialogWindow('create_Incident');
	gDialog.setSize('600','600');
	gDialog.setPreference('sysparm_sysID', sysId);
	gDialog.setPreference('sysparm_number', number);
	gDialog.setTitle('Create Incident');
	gDialog.render();	
}


Workspace CLient script:

	function onClick(g_form) {
	var table = g_form.getTableName();
	var sysId = g_form.getUniqueValue();
	var url = "/create_Incident.do?targetTable=" + table + "&targetId=" + sysId + "&source=agent_workspace";
		g_modal.showFrame({
			url: url,
			title: 'Create Incident',
			size: 'xl'
		});

 

UI Page:

HTML:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

	<g:ui_form>
		<!-- Get values from dialog preferences passed in -->
		<g:evaluate var="jvar_sysId" expression="RP.getWindowProperties().get('sysparm_sysID')" />
		<g:evaluate var="jvar_num" expression="RP.getWindowProperties().get('sysparm_number')" />
		
		<!-- Set up form fields and labels -->

		<input type="hidden" name="ritmSysId" id="ritmSysId" value="${jvar_sysId}"/>
		<input type="hidden" name="ritmNum" id="ritmNum" value="${jvar_num}"/>
		
			<input type="hidden" name="comments" id="comments" value=""/>

			<table width="100%">
				<tr>
					<td>
						<!-- Comments text field (Contains comments from originating record as a default) -->
						<g:ui_multiline_input_field name="dial_comments" id="dial_comments" label="comments" value="${jvar_comments_text}" mandatory="true" />
					</td>
				</tr>
				<tr>
					<td colspan="2">
					</td>
				</tr>
				<tr id="dialog_buttons">
					<td colspan="2" align="right">
						<g:dialog_buttons_ok_cancel ok="return submitRecord();" cancel ="return OnCancel();"/>
						
						
					</td>
				</tr>
			</table>
			</g:ui_form>
		</j:jelly>




Client Script:

function OnCancel() {
//	var c = gel('cancelled');
//	c.value = "true";
	GlideDialogWindow.get().destroy();
//	return false;
}

function submitRecord() {
	var comments = gel("dial_comments").value;
	comments = trim(comments);
	if (comments == "") {
		//If comments are empty stop submission
		alert("Please provide comments to submit the dialog.");
		return false;
	}
	gel("comments").value = comments;
	return true;
}


Processing Script:

var createInc = new GlideRecord("incident");
createInc.initialize();
createInc.parent = ritmSysId;
createInc.u_source = "service_request";
createInc.caller_id = gs.getUserID();
createInc.short_description = "Incident raised for Requested Item " + ritmNum;
createInc.description += "An Incident has been raised for Requested Item " + ritmNum + " with the following comment:<br />" + comments;
createInc.insert();
response.sendRedirect("sc_req_item.do?sys_id=" + ritmSysId);
gs.addInfoMessage("Incident "+ createInc.number+" is created successfully");

1 ACCEPTED SOLUTION

@ramwons 

you are not sending the correct parameter name in the URL

In UI action workspace client script you are sending targetId but in UI page you are checking sysparm_sysID

ensure the parameter name is same so that it works well from both native and agent view

please update workspace client script as below

function onClick(g_form) {
    //var table = g_form.getTableName(); // this is not required
    var sysId = g_form.getUniqueValue();
    var url = "/create_Incident.do?targetTable=" + table + "&sysparm_sysID=" + sysId + "&source=agent_workspace";
        g_modal.showFrame({
            url: url,
            title: 'Create Incident',
            size: 'xl'
        });
}

Also you are not using this line so remove this

<input type="hidden" name="ritmNum" id="ritmNum" value="${sysparm_number}"/>

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

12 REPLIES 12

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Ram,

So it means incident is getting created

Did you check the ritmSysId value is present in the processing script?

any browser console error?

can you try this?

createInc.parent = ritmSysId.toString();

Can you share what you have written in the workspace client script?

I believe it is not able to get the ritmSysId hence not getting the value and not setting

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

 

Yes I checked it. But the ritmSysID value is returning NULL when I create Incident in AW.

But the sysID is returning in UI16.

 

Best Regards,

Ram

Hi Ram,

I believe the RP.getWindowProperties() is not working

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@ramwons 

Below worked well for me in Agent Workspace & Native as well.

Basically I think RP.getWindowProperties() won't work in agent workspace hence the ritmSysId is not being stored there

Updated UI Page Code:

HTML Section:

Remove below 2 lines

<g:evaluate var="jvar_sysId" expression="RP.getWindowProperties().get('sysparm_sysID')" />
<g:evaluate var="jvar_num" expression="RP.getWindowProperties().get('sysparm_number')" />

Update below 2 lines as following

<input type="hidden" name="ritmSysId" id="ritmSysId" value="${sysparm_sysID}"/>
<input type="hidden" name="ritmNum" id="ritmNum" value="${sysparm_number}"/>

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader