Copy Values from another Table into a Form without saving?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2018 02:09 AM
Hi folks,
Hope you can help!
I'm looking for a way to copy field entries I have in a custom table into an incident form, but ideally I'd want to be able to copy the entries and not save them/create a record, more so they appear within the fields and the user has the option to save/edit them before continuing.
I currently have an extra referenced field linking to my custom table, and a UI action that pulls in those fields. The downside is I've done this wrong as it saves and creates the record also.
Essentially i'm looking for a way of emulating the functionality of templates, but cannot actually use templates for this purpose (unless it's possible to link templates into this other table, and call them that way, but I'd prefer another solution if there is one!)
- Labels:
-
Incident Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2018 02:24 AM
Script include is client callable checked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2018 03:35 AM
Hi Abhijeet,
Big thank you for posting this, saves alot of time! Unfortunately, I'm still getting a little trouble with this code.
On selecting the UI action, nothing seems to happen.
I've tried putting in logging, but that didn't seem to output anything to alerts or the log either.
Does it look like i'm missing anything obvious? My custom table name is "u_application_details", which is the same as the reference field on the Incident table.
Script Include
var mandatory = Class.create();
mandatory.prototype = Object.extendsObject(AbstractAjaxProcessor, {
copy_values: function() {
var table = this.getParameter(sysparm_table);
var sys_id = this.getParameter(sysparm_sys_id);
var answer = "";
var gr = new GlideRecord(table);
gr.addQuery("sys_id", sys_id);
gr.query();
if(gr.next())
{
answer = answer + gr.field_name1 + "," + gr.field_name2 + ",";//all the fields value comes here comma seperated
}
alert (answer);
gs.log(answer);
return answer;
},
type: 'copy_values'
});
UI Action
function copy_values()
{
var table = "u_application_details"; // name of the custom table comes here
var ga = new GlideAjax("copy_values");
ga.addParam("sysparm_name", "copy_values");
ga.addParam("sysparm_table", table);
ga.addParam("sysparm_sys_id", g_form.getValue("u_application_details"));
ga.getXMLWait();
var answer = ga.getAnswer();
answer = answer.split(",");
g_form.setValue("u_short_description", answer[0]);
g_form.setValue("u_description", answer[1]);
return false;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2018 03:50 AM
Use this one: Bold was the mistake from me.
UI Action:
onclick: copy_values()
Script:
function copy_values()
{
var table = "table_name"; // name of the custom table comes here
var ga = new GlideAjax("copy_values")
ga.addParam("sysparm_name", "copy_values");
ga.addParam("sysparm_table", table);
ga.addParam("sysparm_sys_id", g_form.getVaue("name of reference field comes here"));
ga.getXMLWait();
var answer = ga.getAnswer();
answer = answer.split(",");
g_form.setValue("field1 on incident form", answer[0]);
g_form.setValue("field2 on incident form", answer[1]);
//and so on
return false;
}
Script Include:
Client Callable is true
Name: copy_values
Script:
var copy_values = Class.create();
copy_values .prototype = Object.extendsObject(AbstractAjaxProcessor, {
copy_values: function() {
var table = this.getParameter(sysparm_table);
var sys_id = this.getParameter(sysparm_sys_id);
var answer = "";
var gr = new GlideRecord(table);
gr.addQuery("sys_id", sys_id);
gr.query();
if(gr.next())
{
answer = answer + gr.field_name1 + "," + gr.field_name2 + ",";//all the fields value comes here comma seperated
}
return answer;
},
type: 'copy_values'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2018 04:37 AM
Still no luck!
Nothing seems to happen on click.
That said, now logging seems to work on the UI Action. It seems return a null value for "answer", but can pull the correct sys_id from the reference field.
If i explicitly declare both the table name and the record's sys id in the script include, the logging pulls through the correct field details, but it still doesn't display them on the form.
Any ideas?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2018 04:47 AM
Put two logs one on the answer in the script include and other an alert on the ui action. Then we can diagnose where the issue lies.