- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2016 12:10 PM
I am building a forms application wherein there is one application for the base forms table, and then additional applications to handle each individual type of form.
All forms extend the base table.
I am trying to create a UI action which will allow users to create a new instance of a form using the current instance, and I need it to work without knowing the actual field names in the given table.
I have created the below Script in the base application, but am running into a strange error which I can't seem to get around.
Function getFields is not allowed in scope x_eqp_forms
My code is below.
Could anyone tell me why I am getting this error and how to get around it??
Thnks!
UI Action |
---|
//query the rows we want to copy var currentForm = new GlideRecord(current.sys_class_name);
|
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2016 01:57 PM
Hi James - below is a possible workaround:
var newForm = new GlideRecord(current.sys_class_name);
var currentFields = [];
newForm.initialize();
for (var f in newForm) currentFields.push(f);
currentFields will then have all field names from newForm.
PS: going one step further, I think you should be able to replace your for loop with the for...in from above.
Please feel free to connect, follow, mark helpful / answer, like, endorse.
John Chun, PhD PMP ![]() | ![]() |
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2016 01:22 PM
All the Scoped and Global API's are documented on the developer portal. Here are the available GlideRecord API's for scoped applications:
You will notice that getFields() is not available in scoped applications. I cannot tell you why unfortunately but that is the reason for your error message. Unfortunately I don't know of a work around either. I would suggest you follow up with support to see if they know of a work around and to possibly open an enhancement to get that API call exposed if possible.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2016 01:57 PM
Hi James - below is a possible workaround:
var newForm = new GlideRecord(current.sys_class_name);
var currentFields = [];
newForm.initialize();
for (var f in newForm) currentFields.push(f);
currentFields will then have all field names from newForm.
PS: going one step further, I think you should be able to replace your for loop with the for...in from above.
Please feel free to connect, follow, mark helpful / answer, like, endorse.
John Chun, PhD PMP ![]() | ![]() |
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2016 02:45 PM
Thank You !!!!!!!!!!!!!
That was exactly what I needed!!
Here is the revised script:
//Get Current Form
var currentForm = new GlideRecord(current.sys_class_name);
if(currentForm.get(current.sys_id)){
var newForm = new GlideRecord(current.sys_class_name);
newForm.initialize();
//Get Field Names for Current Form
var currentFieldNames = [];
for (var f in currentForm) currentFieldNames.push(f);
//Copy current form's values into a new form
for (var i = 0; i < currentFieldNames.length; i++) {
//make sure we don't copy the sys_id etc
if((currentFieldNames[i] != 'sys_id')&&(currentFieldNames[i] != 'number')&&(currentFieldNames[i] != 'sys_mod_count')&&(currentFieldNames[i] != 'sys_tags')&&(currentFieldNames[i] != 'approval'))
{
newForm.setValue(currentFieldNames[i], currentForm.getValue(currentFieldNames[i]));
}
}
//Insert the new form
var newSysId = newForm.insert();
gs.addInfoMessage(newForm.sys_class_name.getDisplayValue() + ' ' + newForm.number + ' has been created using ' + currentForm.number + '. Please review the new eForm for accuracy before submitting for Approval.');
action.setRedirectURL(newForm);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2017 04:09 PM
and if you exclude 'sys_class_type' you can copy all content of one record from another table. The following works on an existing record:
copyAllParentVariables: function(child)
{
var scopeName=gs.getCurrentScopeName();
var parent= new GlideRecord(scopeName+'_request'); // this is the parent table. your child record needs to be precreated but can be in any table.
parent.addQuery('serial_number', child.serial_number.trim());
parent.query();
parent.next();
if(parent.get(parent.sys_id)){
var currentFieldNames = [];
for (var f in parent) currentFieldNames.push(f);
//Copy current form's values into a new form
for (var i = 0; i < currentFieldNames.length; i++) {
if( (currentFieldNames[i] != 'sys_class_name') && (currentFieldNames[i] != 'task_type') && (currentFieldNames[i] != 'sys_id')&&(currentFieldNames[i] != 'serial_number') && (currentFieldNames[i] != 'number')&&(currentFieldNames[i] != 'sys_mod_count')&&(currentFieldNames[i] != 'sys_tags')&&(currentFieldNames[i] != 'approval'))
{
child.setValue(currentFieldNames[i], parent.getValue(currentFieldNames[i]));
}
}
child.update();
}
},