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

How do I map all variables into the description field & activity log from a record producer

ToniOxley
Kilo Expert

Good Afternoon!

I have created a new record producer for our "Log an incident form" - its quite complex and includes a few different ui policies (for example, if category is protection then show the the protection variable set) - currently i have all the new variables added to the form and the UI policies and actions working perfectly on the front end catalogue form, but on submission, none of the completed fields are been pulled through to the back end incident.

 

Can you please advise how i can get this working?

 

thank you very much ... just an example...

This is our front end form...

As you can see, nothing is mapped across to the back end...

I'm aware its something here that we have to amend...

can you please advise the following;

- what script i need to include all of the completed variables only into the incident record

- how i can amend this going forward if we include more variables sets within the incident record producer

- How i can map all completed variables into the activity log

 

Thank you

18 REPLIES 18

Sam Motley
Giga Guru

hi all, 

any chance of getting some assistance pulling just one of these answers into a form field?

looking to get free text of 1 question into the short description 

 

cheers 

current.fieldName = producer.variableName;   

 

Simple as that.
And also SUPER secret trick, if the variable name has the same name as the field, the record producer will do it automagically.

Thanks Robert much appreciated 🙂 

Skander
Tera Contributor

I am a little late to the party but here is a Business Rule (Before) we created for a client to copy all the variables to the description for Record Producers. It is not complete. Depending on the field types that you need other than these: Reference, List collector, Select Box , Single and Multiple Line Text. Also it takes care of empty variables.

 

(function executeRule(current, previous /*null when async*/ ) {
	
	var type, name, value, reference, val, item;
    var producerVars = new GlideRecord('question_answer');
    producerVars.addQuery('table_sys_id', current.sys_id);
    //Exclude Label and Container variables
    producerVars.addQuery('question.type', '!=', 11);
    producerVars.addQuery('question.type', '!=', 19);
    producerVars.addQuery('question.type', '!=', 20);
    // Set Order
    producerVars.orderBy('order');
    producerVars.query();
    var descriptionBuilder = '';
    while (producerVars.next()) {
        if (producerVars.value) {
            //Add variable names and values to the description
            type = producerVars.question.type.toString();
            name = producerVars.question.question_text.toString();
            val = producerVars.value.toString();
            // Reference
            if (type == 8 ) {
                reference = producerVars.question.reference.toString();
                value = getReferenceDisplayValue(reference, val);
                descriptionBuilder += (name + ":   " + value + "\n");
            }
            // Select Box
            else if (type == 5) {
                item = producerVars.question.sys_id;
                value = getChoiceDisplayValue(item, val);
                descriptionBuilder += (name + ":   " + value + "\n");
            }
            // List Collector
            else if (type == 21) {
                var valSplit = val.split(',');
				var arr = [];
                for (i = 0; i < valSplit.length; i++) {
                    value = getChoiceDisplayValueList(valSplit[i]);
					arr.push(value);
					arr.join(',');
                }
				descriptionBuilder += (name + ":   " + arr + "\n");
            }
            // Default
            else {
                value = val;
                descriptionBuilder += (name + ":   " + val + "\n");
            }

            // Replace blank values with
            if (value == '') {
                value = '';
            }
        }
    }
    current.description = descriptionBuilder;
    // Function to convert reference value to display value
    function getReferenceDisplayValue(table, value) {
        var displayValue1 = '';
        var gr1 = new GlideRecord(table);
        gr1.addQuery('sys_id', value);
        gr1.query();
        if (gr1.next()) {
            displayValue1 = gr1.getDisplayValue();
        }
        return displayValue1;
    }
    // Function to convert choice value to display value
    function getChoiceDisplayValue(item_option, value) {
        var displayValue2 = '';
        var gr2 = new GlideRecord('question_choice');
        gr2.addEncodedQuery('question=' + item_option + '^value=' + value);
        gr2.query();
        if (gr2.next()) {
            displayValue2 = gr2.text + '';
        }
        return displayValue2;
    }
	// Function to convert choice value to display value for List Collector
    function getChoiceDisplayValueList(value) {
        var displayValue2 = '';
        var gr2 = new GlideRecord('question_choice');
        gr2.addEncodedQuery('sys_id=' + value);
        gr2.query();
        if (gr2.next()) {
            displayValue2 = gr2.text + '';
        }
        return displayValue2;
    }
})(current, previous);