- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2023 01:57 PM - edited ‎08-07-2023 02:02 PM
I have a record producer that has a catalog UI policy in place. Here is an example of how it works:
If someone selects a type such as 'Employee' (which is part of a selection list) for Variable 1 'Type'
Then Variable 2 'Employee Request' appears with its own set of selections (such as, add an employee or deactivate an employee)
If someone selects a type such as Contractor (which is part of a selection list) for Variable 1 'Type'
Then Variable 2 'Contractor Request' appears with its own set of selections (such as, add a contractor or deactivate a contractor)
Eventually, the 'Contractor' type and 'Contractor Request' variables were deactivated but there were existing records that used that selection, so I had to create a background script to update existing records to point to the Employee type in Variable 1 and Employee Request in Variable 2 since the Contractor variables have been deactivated but for some reason, I'm unable to update Variable 2. Not only will it not update, but the field won't even appear on the target record.
This is the background script I put together, which works for the most part:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2023 05:12 AM
You need to make sure that an entry for the generated record-variable combo exists in table question_answer. If at the time of submitting the record producer Employee Request was not part of the Record Producer, such an entry has not been generated and simply running
user_record.variables.request = ...
will not generate it.
I mean my guess is that the update is not happening (and the variable is not showing) because it does not exist as a record.
But - as said above - it is easy to check this, just see if the required record in question_answer exists.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2023 05:12 AM
You need to make sure that an entry for the generated record-variable combo exists in table question_answer. If at the time of submitting the record producer Employee Request was not part of the Record Producer, such an entry has not been generated and simply running
user_record.variables.request = ...
will not generate it.
I mean my guess is that the update is not happening (and the variable is not showing) because it does not exist as a record.
But - as said above - it is easy to check this, just see if the required record in question_answer exists.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2023 01:16 PM
Thank you! This was exactly the case. The combo was missing from the question_answer table. Once I had added a record with that variable combination for the record's sys_id, I was able to see the variable and was able to apply those changes. Thanks so much!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2023 01:34 AM
You're welcome 🙂
Also thanks for marking the correct answer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2023 06:50 AM
Hi @neil_b
something like this -
var user_record = new GlideRecord('request');
user_record.addEncodedQuery('number=12345');
user_record.query();
while (user_record.next()) {
user_record.variables.type.setValue('Employee');
user_record.variables.request.setValue('Add an Employee');
// Insert the record to ensure variables and question_answer records are created
if (user_record.insert()) {
gs.log("Updated request: " + user_record.number);
} else {
gs.log("Failed to update request: " + user_record.number);
}
}
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Regards,
Tushar