The CreatorCon Call for Content is officially open! Get started here.

Script check to get value

akin9
Tera Contributor

Hello Experts,

We have "product inventory" table having "account field " and under that "Product characteristics" related lists available.

Requirement.

Account having "TSP" field and one "TSP" field on the interaction.

1.After creating a interaction Product.account.Tsp value need to update in the Interaction

Based on below script query mets. but below script is not working as expected 

please correct me.

BR :After : Insert/update .

Table: Interaction.

 

(function executeRule(current, previous) {
    var account = current.account.toString();
    var inventory = new GlideRecord('sn_prd_invt_product_inventory');
    inventory.addQuery('account', account);
    inventory.query();
 
    while (inventory.next()) {
   
        var characteristic = new GlideRecord('sn_prd_pm_product_characteristics');
        characteristic.addQuery('inventory', inventory.sys_id);
        characteristic.addEncodedQuery('characteristic.nameSTARTSWITHadditionalInfo^characteristic_valueLIKE"telecomServicePriority"')
        characteristic.query();
 
        if (characteristic.next()) {
           current.u_tsp = inventory.account.u_tsp_level;
            current.update();
            break;
        }
    }
})(current, previous);
 
 
8 REPLIES 8

Sandeep Rajput
Tera Patron
Tera Patron

@akin9 Please see if this works.

(function executeRule(current, previous) {
    var account = current.account.toString();
    var inventory = new GlideRecord('sn_prd_invt_product_inventory');
    inventory.addQuery('account', account);
    inventory.query();
 
    while (inventory.next()) {
   
        var characteristic = new GlideRecord('sn_prd_pm_product_characteristics');
        characteristic.addQuery('inventory', inventory.sys_id);
        characteristic.addEncodedQuery('characteristic.nameSTARTSWITHadditionalInfo^characteristic_valueLIKE"telecomServicePriority"');
        characteristic.query();
 
        if (characteristic.next()) {
           current.u_tsp = inventory.account.u_tsp_level.toString();
            current.update();
            break;
        }
    }
})(current, previous);

 

If the above script doesn't work then check if the following query is returning any result or not.

 

 var characteristic = new GlideRecord('sn_prd_pm_product_characteristics');
        characteristic.addQuery('inventory', inventory.sys_id);
        characteristic.addEncodedQuery('characteristic.nameSTARTSWITHadditionalInfo^characteristic_valueLIKE"telecomServicePriority"')
        characteristic.query();
 
        if (characteristic.next()) {
           current.u_tsp = inventory.account.u_tsp_level;
            current.update();
            break;
        }

 

Try to run this as a background script and see if it returns any result. 

akin9
Tera Contributor

Hi @Sandeep Rajput @AshishKM 

Thank you for your sharing it was helpful to achieve my scenarios.

@akin9 Could you please mark the response an accepted solution if it managed to address your question.

@akin9 , second to @Sandeep Rajput

System allow to accept more that one reply as accepted solutions. 

 

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution