Copying Multiple Fields using a UI Action

fanare
Giga Contributor

Hello,

I was wondering if it was possible to have a UI action on the incident form that when pressed would pull 4 fields from the form. (For example: I would like to pull : Number, Company, Short Description and Priority)

I looked around the community forums and found this:

var field = g_form.getValue('fieldname');

window.prompt("Copy to clipboard: Ctrl+C, Enter", field);

The only problem is that, it only copies 1 field. I need as way to copy 4 fields and make it easy to copy to clipboard if possible.

I'm looking into using GlideDialogWindows but i'm unfamiliar with UI Pages at the moment. Any help would be appreciated.

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

If you just want the values comma delineated you could do something like:

var fieldArr = ['number','company','short_description','priority'];
var fieldValues = [];
for (var i = 0; i < fieldArr.length; i++) {
	fieldValues.push(g_form.getValue(fieldArr[i]));
}
window.prompt("Copy to clipboard: Ctrl+C, Enter", fieldValues.join());

You can add or change fields by changing the fieldArr array variable.

View solution in original post

3 REPLIES 3

Brad Tilton
ServiceNow Employee
ServiceNow Employee

If you just want the values comma delineated you could do something like:

var fieldArr = ['number','company','short_description','priority'];
var fieldValues = [];
for (var i = 0; i < fieldArr.length; i++) {
	fieldValues.push(g_form.getValue(fieldArr[i]));
}
window.prompt("Copy to clipboard: Ctrl+C, Enter", fieldValues.join());

You can add or change fields by changing the fieldArr array variable.

Hi Brad

I have similar type of requirement. On clicking of UI button, it should push 4 field value to worknotes field, then form should be save and those four field should blank after the values copied to worknotes. Please suggest how to implement this.

fanare
Giga Contributor

Perfect! That worked. Thank you. Much simpler than trying using UI Pages 🙂