Applying standard change template from script not setting all the fields

Sam Ogden
Tera Guru

Hi All,

In a UI action on the sc_task table I am calling the following script to create a standard change:

createChange: function(template, templateID) {

        var dates = this.calculateDates();
        var createChng = new GlideRecord('change_request');
        createChng.initialize();
        createChng.type = 'standard';
        createChng.start_date = dates.start_date;
        createChng.end_date = dates.end_date;
        createChng.std_change_producer_version = templateID;
        createChng.applyTemplate(template);
        createChng.insert();

        return createChng;
    },

 

This is setting most of the fields from the standard change template apart from 'description, short_sescription' & u_service' fields.  Having a bit more a look into this, these 3 fields are the only fields from the template which we don't have in the 'read only' property under the standard change properties.  If I add them to this property then re-run the script it creates a standard change and sets these 3 fields.

Any help on why when the 3 fields are not included in the read only standard change property they do not get applied?

I have checked and if I manually select the template from the standard change catalog and the fields are not in the red only property they still get set, it seems to only be when using the script?

Thanks

Sam

1 ACCEPTED SOLUTION

Sam Ogden
Tera Guru

I reached out to HI in the end with the issue being with the business rule 'Apply standard change template'.  This is a display business rule, so does not run when trying to set the template from a script (manually selecting the template takes you to the record to submit).

I had to replicate the logic in the business rule within my script

Hope this helps

Thanks

Sam

View solution in original post

6 REPLIES 6

Hi @samogden 

I am facing the same issue, could you please share the script which worked for you?

Thanks,

Prajakta

Hi Prajakta,

I have changed jobs since this so no longer have access to the script.  From memory I think it was the business rule 'Apply standard change template' on the change_request table that was the issue, so I had to change the script to add the template in the same way as the business rule works.

Apologies couldn't offer more help from memory.

Thanks

Sam