- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2014 07:52 PM
why cant you insert a record directly into the table and set the values to the fields required? the workflow should get attached after the record insertion too.
the above script is some serious writing but if it can be done at table record insertion, why go to the record producer route...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2020 07:48 AM
In my case, i have the record and i am just trying to insert the catalog variables in question_answer table. I was able to insert the variables into question_answer table and the variables appear in my record as well but none of the ui policies/client scripts related to those variable runs.
Did you face these issues and try to resolve it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2014 09:02 PM
Hi Sachin,
Requirement is not that much clear... Are you trying to create the change request through record producer with help of transform script?
Transform map is used to create / update the record, so you can create a request with help of transform map itself.. And workflow will get attached, once you insert a new record in the change request table...
You can able to accomplish through transform script but i am not sure why you are trying to through transform script..
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2018 01:14 AM
I have updated this script include as mentioned above to cope for scoped application development.
- replace gs.print with gs.info
- Replace applyTemplated with Scoped equivalent
- Added execution of the script block within the record producer:
Some special note on this, the variable producer is not available in this script at this point. Current though works just fine.
var Base_RecordProducer = Class.create();
Base_RecordProducer.prototype = {
initialize: function(producerSysId) {
this.producerSysId = producerSysId;
this.producer = this.getProducer(producerSysId);
this.targetTable = this.producer.table_name;
this.userVariables = {};
this.rpVariables = this.prepRecordProducerVariables();
gs.info("producerSysId: " + producerSysId);
gs.info("target table: " + this.targetTable);
},
getProducer: function(producerSysId) {
var gr = new GlideRecord("sc_cat_item_producer");
if (gr.get(producerSysId)) {
gs.info("Yep, we found the RP: " + gr.name);
return gr;
}
return null;
},
setVariable: function(name, value) {
this.userVariables[name] = value;
},
setVariables: function(variableObject) {
this.userVariables = variableObject;
},
submit: function() {
var targetRecord = new GlideRecord(this.targetTable);
targetRecord.initialize();
if (!gs.nil(this.producer.template)) {
var template = new GlideTemplate.get(this.producer.template);
template.apply(targetRecord);
}
var v;
// Set mapped fields on target record
for (v in this.rpVariables) {
if (this.rpVariables[v].mapToField == true) {
targetRecord.setValue(this.rpVariables[v].field, this.userVariables[v] || "");
}
}
// execute script part of Record Producer
var _evaluator = new GlideScopedEvaluator();
_evaluator.putVariable('current', targetRecord);
_evaluator.putVariable('producer', this.userVariables);
var _evaluator_result = _evaluator.evaluateScript(this.producer, 'script');
var targetSysId = targetRecord.insert();
// if there's no target sys_id, don't create any question_answer entries
if (targetSysId)
{
// One more loop - insert variables in question_answer table
var qa;
for (v in this.rpVariables) {
qa = new GlideRecord("question_answer");
qa.initialize();
qa.question = this.rpVariables[v].sysId;
qa.order = this.rpVariables[v].order;
qa.table_name = this.targetTable;
qa.table_sys_id = targetSysId;
qa.value = this.userVariables[v];
qa.insert();
}
}
return targetSysId;
},
prepRecordProducerVariables: function() {
var variables = {};
var grItemOption = new GlideRecord("item_option_new");
grItemOption.addQuery("cat_item", this.producerSysId);
grItemOption.query();
while (grItemOption.next()) {
var obj = {};
var name = grItemOption.getValue("name");
obj.field = grItemOption.getValue("field");
obj.mapToField = grItemOption.getValue("map_to_field");
obj.sysId = grItemOption.getValue("sys_id");
obj.order = grItemOption.getValue("order");
variables[name] = obj;
}
return variables;
},
type: 'Base_RecordProducer'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2020 07:45 AM
i followed a similar approach and created the entries in question_Answer table but the catalog ui policies and the catalog client scripts are not working on the form.
Did anybody fix this issue?