Record Producer to create new change and apply template to the change

bwilson2
Tera Contributor

I have created a Record Producer in the service catalog that contains a Lookup Select Box that shows a list of templates by their short description. What I would like to happen is when the user selects a template from the Lookup Select Box a new change is created and the specific template they selected is applied to the newly created change. Right now I have a template statically assigned in the tab labeled "Generated Record Data" in the record producer screen. So no matter what template they select from the Lookup Select Box, the template that I have statically assigned is applied to the change that is created.

Is there a way to apply the template that the user selects from the Lookup Select Box to apply to the new change, using a record producer?

Ex: Lookup Select Box options:

        Template A

        Template B

        Template C

If the user selects Template C, then Template C would be applied to the new change created by the Record Producer. I know this could be accomplished using multiple Record Producer's, one for each template. However, I am wondering if I could accomplish this using a single Record Producer.

Any suggestions?

1 ACCEPTED SOLUTION

In your lookup select box, make sure the Lookup value field in the Type Specifications section is the set to the name of the template as that is what the applyTemplate function is expecting.   then in your script you would have:


current.applyTemplate(producer.LookupSelectBoxVariableName);



The producer.LookupSelectBoxVariableName value would be set to the Template name chosen.


View solution in original post

15 REPLIES 15

In your lookup select box, make sure the Lookup value field in the Type Specifications section is the set to the name of the template as that is what the applyTemplate function is expecting.   then in your script you would have:


current.applyTemplate(producer.LookupSelectBoxVariableName);



The producer.LookupSelectBoxVariableName value would be set to the Template name chosen.


Thank you very much for taking the time to walk me through this. I appear to have gotten it to work how I was expecting it to work. I was setting the Lookup value field to short description instead of name which is why the script wasn't working properly.


Cool, glad you got it working.



If you prefer the drop down display the short description of the template instead of the name, set the Lookup label field(s) value to short_description.   This will make the display value be the short description, but the actual value for the variable be the name.   Now this said, just make sure all of your templates have a Short Description set otherwise there will be blank rows that show up.


Brandon, just to make sure you are good, I just tested out my idea and it works.   I created a simple record producer to create a change request.



  1. Table is set to Change Request(change_request)
  2. Created 1 variable of type Lookup Select Box where I set the Question to Template and the name value to template (name is important to note as that is used in the record producer script.
    1. In the type specifications section I set the following:
    2. find_real_file.png
    3. Notice I also included a reference qualifier to only show the templates for the change_request table
  3. Then in the Record Producer script, I have 2 lines of script, 1 to apply the template chosen in the variable and another to provide a message to the user confirming the record was created using the template chosen.   Feel free to edit the message to your liking.
    1. current.applyTemplate(producer.template);


    2. gs.addInfoMessage(current.getClassDisplayValue() + " created using the " + producer.template + " template.");


Stefan42
Tera Expert

If you would like to apply a standard change template you can use this solution i created.

Add the following code to your record producer script section:

// Get standard change template information and apply template
var gr = new GlideRecord('std_change_producer_version');
gr.get('std_change_producer', producer.<INSERT_TEMPLATE_SYS_ID_VARIABLENAME_HERE>);

current.std_change_producer_version = gr.sys_id;
current.applyTemplate(gr.std_change_producer.template.getDisplayValue());