Catalog Client Script on target record is not working

IAmIshan
Tera Guru

We have a record producer that users are using to submit requests. Additionally, we are also submitting requests through scripts.

  • UI Type: All

  • Applies on Target Record: True

Now, the issue is:
When the request is submitted by an end user via the record producer, the catalog client script works as expected.
However, when the request is created through a script, the catalog client script does not run.

Scenario:

Based on the value of one variable, we need to make another variable visible and mandatory.
We considered using a table-based OnChange client script, but since variables are not available in the 'Field Name'dropdown, it seems this approach won't work.

Can anyone please suggest how we can handle this scenario when the request is submitted through a script?

 

2 REPLIES 2

J Siva
Tera Sage

Hi @IAmIshan 
Could you share sample request screenshots for when it's submitted manually and when it's submitted via script?
Regards,
Siva

Ryan166
Tera Contributor

Hello There, 

 

I recently had the same issue and was able to resolve this by fixing the script producing the target record. The main issue for me was that the script generated record was not considered as a target record. 


When duplicating record inside a record producer script you must create a new record inside the 'sc_item_produced_record' table as follows : 


// First we create the record inside the target table

 var grNew = new GlideRecord(<insert your target table>);
 grNew .initialize();
 grNew = grXV2GDG.insert();

var itProducer = new GlideRecord('sc_item_produced_record');
itProducer.initialize();
itProducer.setValue("producer", <insert your record producer sys_id>);
itProducer.setValue("task", grNew); 
itProducer.setValue("record_key", grNew); // This field is what makes the record generated considered as a target record
itProducer.setValue("record_table", <insert your target table>);
itProducer.insert();


With this setup your Catalog Client Script and Catalog UI Policy (having Applies on Target Record = True) should trigger properly on the script generated target record. 

Hope it helps 😉