"sp-variable-editor" widget variables

Hafsa1
Mega Sage

There is oob widget "sp-variable-editor". I have cloned it and used it in CSM case page in portal.

suppose, we raise case via record producer with 20 variables filled out of 50 variables.

Problem is that it is showing all 50 variables in variable editor, requirement is to only show which is not empty(filled ones)

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Hafsa1 

in that cloned widget update these 2 functions getValuesForProducer() and getValues() present in server side

function getValues(table, sys_id, task_id, opened_by) {
    var qs = new GlideappVariablePoolQuestionSet();
    if (table == "sc_cart_item")
        qs.setCartID(sys_id);
    else if (table == "sc_task") {
        qs.setRequestID(sys_id);
        qs.setTaskID(task_id);
    } else {
        qs.setRequestID(sys_id);
    }

    qs.load();
    var values = {};
    var questions = qs.getFlatQuestions().toArray();
    for (var i = 0; i < questions.length; i++) {
        var q = questions[i];
        if (q.getValue()) {
            var o = {
                value: q.getValue(),
                displayValue: q.getDisplayValue(),
                type: q.getType()
            };
            //handling List Collector (21) and Masked (25) variables.
            if (o.type == 21)
                o.display_value_list = q.getDisplayValues().toArray();
            if (o.type == 25 && q.canDecrypt(opened_by, table))
                o.decrypted_value = q.decrypt(o.value);
            var qKey = q.getName();
            if (typeof qKey == 'undefined' || qKey == '')
                qKey = "IO:" + q.getId();
            values[qKey] = o;
        }
    }
    return values;
}
function getValuesForProducer(table, sys_id, opened_by) {
    var qs = new GlideappSequencedQuestionSet();
    qs.setTableName(table);
    qs.setTableSysID(sys_id);

    qs.load();
    var values = {};
    var questions = qs.getFlatQuestions().toArray();
    for (var i = 0; i < questions.length; i++) {
        var q = questions[i];
        if (q.getValue()) {
            var o = {
                value: q.getValue(),
                displayValue: q.getDisplayValue(),
                type: q.getType()
            };
            //handling List Collector (21) and Masked (25) variables.
            if (o.type == 21)
                o.display_value_list = q.getDisplayValues().toArray();
            if (o.type == 25 && q.canDecrypt(opened_by, table))
                o.decrypted_value = q.decrypt(o.value);
            var qKey = q.getName();
            if (typeof qKey == 'undefined' || qKey == '')
                qKey = "IO:" + q.getId();
            values[qKey] = o;
        }
    }
    return values;
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Jagadeesh5
Tera Contributor

Hi,

   Please try the following solution. I haven't tried the script, but I believe this should work. Create an onload catalog client script in record producer and select the checkbox says Applies on target record. And add type as Mobile/Service Portal. Once added add the following script

   

var fields = g_form.getEditableFields();
 
for (var x = 0; x < fields.length; x++) {
if(!g_form.getValue(fields[x])){
g_form.setDisplay(fields[x],false)
}
}

Ankur Bawiskar
Tera Patron
Tera Patron

@Hafsa1 

in that cloned widget update these 2 functions getValuesForProducer() and getValues() present in server side

function getValues(table, sys_id, task_id, opened_by) {
    var qs = new GlideappVariablePoolQuestionSet();
    if (table == "sc_cart_item")
        qs.setCartID(sys_id);
    else if (table == "sc_task") {
        qs.setRequestID(sys_id);
        qs.setTaskID(task_id);
    } else {
        qs.setRequestID(sys_id);
    }

    qs.load();
    var values = {};
    var questions = qs.getFlatQuestions().toArray();
    for (var i = 0; i < questions.length; i++) {
        var q = questions[i];
        if (q.getValue()) {
            var o = {
                value: q.getValue(),
                displayValue: q.getDisplayValue(),
                type: q.getType()
            };
            //handling List Collector (21) and Masked (25) variables.
            if (o.type == 21)
                o.display_value_list = q.getDisplayValues().toArray();
            if (o.type == 25 && q.canDecrypt(opened_by, table))
                o.decrypted_value = q.decrypt(o.value);
            var qKey = q.getName();
            if (typeof qKey == 'undefined' || qKey == '')
                qKey = "IO:" + q.getId();
            values[qKey] = o;
        }
    }
    return values;
}
function getValuesForProducer(table, sys_id, opened_by) {
    var qs = new GlideappSequencedQuestionSet();
    qs.setTableName(table);
    qs.setTableSysID(sys_id);

    qs.load();
    var values = {};
    var questions = qs.getFlatQuestions().toArray();
    for (var i = 0; i < questions.length; i++) {
        var q = questions[i];
        if (q.getValue()) {
            var o = {
                value: q.getValue(),
                displayValue: q.getDisplayValue(),
                type: q.getType()
            };
            //handling List Collector (21) and Masked (25) variables.
            if (o.type == 21)
                o.display_value_list = q.getDisplayValues().toArray();
            if (o.type == 25 && q.canDecrypt(opened_by, table))
                o.decrypted_value = q.decrypt(o.value);
            var qKey = q.getName();
            if (typeof qKey == 'undefined' || qKey == '')
                qKey = "IO:" + q.getId();
            values[qKey] = o;
        }
    }
    return values;
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hafsa1
Mega Sage

this widget is visible for all CSM cases. I want to show only for specific case where "category=invoice" and "status=12"?

@Hafsa1 

you will have to enhance the code from your side.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader