Catalog item - business rule

Alex-Lima84
Tera Contributor

Hello.

 

I'm trying to save my catalog variables in my custom table fields with an After Business Rule. Could anyone tell my why this isn't working? Or should I script it differently. I want to save them after I submit my catalog item.

(function executeRule(current, previous /*null when async*/ ) {
    try {
        var variables = current.variables;

        var customTable = new GlideRecord('x_976040_app_pro_job_application_process');
        customTable.initialize();

        customTable.ritm_number = current.number;
        customTable.full_name = variables.app_full_name;
        customTable.zip_code = variables.app_zip_code;
        customTable.address = variables.app_address;
        customTable.address_number = variables.app_address_number;
        customTable.neighborhood = variables.app_address_neighborhood;
        customTable.city = variables.app_address_city;
        customTable.candidate_state = variables.app_address_state;
        customTable.e_mail = variables.app_email;
        customTable.contact_number = variables.app_number;
        customTable.introduction_info = variables.app_introduction_text;
        customTable.resume = variables.app_upload_resume;

        customTable.insert();
    } catch (ex) {

        gs.error('An error occurred in the business rule: ' + ex);
        throw ex;
    }
})(current, previous);
1 ACCEPTED SOLUTION

Make the business rule an After business rule and check if a record already exists for the RITM

(function executeRule(current, previous /*null when async*/ ) {
    try {
        var variables = current.variables;

        var customTable = new GlideRecord('x_976040_app_pro_job_application_process');
        customTable.addQuery('ritm_number',current.number); // if using sys_id, replace number with sys_id
        customTable.query();

       if (!customTable.next())
       {
        customTable.initialize();

        customTable.ritm_number = current.number;
        customTable.full_name = variables.app_full_name;
        customTable.zip_code = variables.app_zip_code;
        customTable.address = variables.app_address;
        customTable.address_number = variables.app_address_number;
        customTable.neighborhood = variables.app_address_neighborhood;
        customTable.city = variables.app_address_city;
        customTable.candidate_state = variables.app_address_state;
        customTable.e_mail = variables.app_email;
        customTable.contact_number = variables.app_number;
        customTable.introduction_info = variables.app_introduction_text;
        customTable.resume = variables.app_upload_resume;

        customTable.insert();
}
    } catch (ex) {

        gs.error('An error occurred in the business rule: ' + ex);
        throw ex;
    }
})(current, previous);

 


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

6 REPLIES 6

Can you post your current BR script and on which table are you running it?


Please mark this response as correct or helpful if it assisted you with your question.

I solved the issue. I accidentally checked the Update checkbox on the when to run. I think it was running multiple times due to this.

 

Thank you @SanjivMeher 🙂