Background Script and Catalog UI Policy Conflicts

neil_b
Tera Guru

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:

var user_record = new GlideRecord('request');
user_record.addEncodedQuery('number=12345');
user_record.query();

while(user_record.next()){
    user_record.variables.type = 'Employee';
    user_record.variables.request = 'Add an Employee';
    user_record.setWorkflow(false);
    user_record.update();
}
 
The first variable was successfully updated from Contractor to Employee but the second variable is not updating AND it is hidden from the screen (due to the catalog UI policy). I'm not sure how I can update the second variable for existing records. If I create a new record, the catalog UI policy works just fine and shows the second variable as expected but I can't get the second variable to appear for existing records that were updated via background script.
1 ACCEPTED SOLUTION

-O-
Kilo Patron
Kilo Patron

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.

View solution in original post

5 REPLIES 5

This was mostly great, because it added the missing variable that I needed to the table, but I still ran into a few issues. I copied the code verbatim into my background script and after running the script, it ended up duplicating my requests, so now I have (2) 12345's. I was able to get around this without a background script and just manually inserting a new record to the question_answer table. Thank you!