How do I call a script include from the mobile agent?

kimberlylp
Giga Guru

I have a UI Action to copy a task. It calls a script include with the following code:

var copyToNewTask = new u_task_utility();
var newTask = copyToNewTask.copyTask();
 
When I try to call the same script include from the mobile agent Action, the screen hangs. I'm assuming the agent does not pass in current, so I tried passing in input and setting current = input; the screen still hangs.
1 ACCEPTED SOLUTION

kimberlylp
Giga Guru

Service Now support informed me there is no way to read/display the return message from a script include. I only have access to the record in hand. They suggested I create a column and write the response in it to display.

 

Since I am creating a copied task, I chose to write to the correlation_id column then display that in the Success Message. Not ideal because the message is only displayed for 5 seconds. I'll just need to inform my end users to quickly write it down or memorize it as there is no copy/paste in this app (what's up with that!?!).

 

Success message = {{correlation_id}}

View solution in original post

5 REPLIES 5

Brad Tilton
ServiceNow Employee
ServiceNow Employee

I don't think input will be the same as current. You'll likely need to construct an object and pass it into your script include with specific values. What happens when you try to debug this process? Are there any errors? 

Hi Brad,

I'm very new to apps. This whole thing is a learning curve for me and there is not much documentation provided by Service Now. How do you debug a mobile app?

What I have managed to do is find that input has an input.sys_id. Since I know it's a task, I've done the following (note incident_task, change_task and problem_task use this function):

copyTask: function (SysID) {
//gs.log('[' + new Date().getTime() + '] SysID = ' + SysID, 'copyTask Task Utility');

vargdt=newGlideDateTime();
vartableName;
varusr=gs.getUserID();
varteam='';

if (SysID) {
//find the task type
vargetCurrent=newGlideRecord('task');
getCurrent.get(SysID);
tableName=getCurrent.sys_class_name.getValue();
//get the record from the specific table
vargetCurrentFromTable=newGlideRecord(tableName);
getCurrentFromTable.get(SysID);
//set current
current=getCurrentFromTable;
} else {
tableName=current.getTableName();
}
//gs.log('[' + new Date().getTime() + '] tableName = ' + tableName, 'copyTask Task Utility');
vargr=newGlideRecord('sys_user');
gr.addQuery('sys_id', usr);
gr.query();
if (gr.next()) {
team=gr.u_team;
}

varnewTask=newGlideRecord(tableName);
newTask.initialize();
 
//selected fields to copy
newTask.u_task_list=current.cmdb_ci;
newTask.u_task_list=current.u_task_list;
newTask.priority=current.priority;
newTask.u_created_by=usr;
newTask.u_created_by_team=team;
newTask.u_assigned_to_team=current.u_assigned_to_team;
newTask.short_description=current.short_description;
newTask.description=current.description;
newTask.u_address_type=current.u_address_type;
newTask.u_address=current.u_address;
newTask.u_assigned_date=gdt;
newTask.insert();
 
gs.addInfoMessage(current.number+' Task copied to '+newTask.number);

},

What I'm struggling with now is how to display the return in an info message to let the user know what task number was created.

I don't think you'll be able to show an info message on mobile, but you can show success and failure messages on an action. I can't remember how dynamic those are, though.