Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Need help for On change client script and Script include to print data

Divya Kandula
Kilo Guru

Hi Need help for below client script and Script Include

 

Client Script:
 ==============================================================

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var code = g_form.getValue('u_commodity_code');
    if (g_scratchpad.isGreenLaneRecord == true) {
        var desc = new GlideAjax('FJS_DeclarationGoodsUtilsAjax');
        desc.addParam('sysparm_name', 'getCommodityHierarchy');
        desc.addParam('sysparam_code', code);
        desc.getXML(hierarchyDesc);
    }


    function hierarchyDesc(response) {

        var answer = response.responseXML.documentElement.getAttribute("answer");
        g_form.setValue('u_commodity_code_hierarchy', answer);
    }
}
===================================================================
Script Include:

getCommodityHierarchy: function() {
		var code = this.getParameter("sysparam_code");
        var comHierarchy = '';
        var goodsDesc = '';
        var grCC = new GlideRecord('sn_customerservice_commodity_code');
        grCC.addEncodedQuery('u_commodity_code' + code); //u_goods_descriptionSTARTSWITHOther^
        grCC.query();
        if (grCC.next()) {
            var hierDesc = grCC.u_hierarchy_description;
            comHierarchy = hierDesc.replace(/[||]+/g, '\n');
            goodsDesc = grCC.u_goods_description;
        }
        var Desc = 'Commodity Code: ' + code + '\n' + 'Commodity Code Description: ' + goodsDesc + '\n' + 'Hierarchy Description: ' + '\n' + comHierarchy;
		return Desc;


    },

i need  to set "u_commodity_code_hierarchy" value with three fields from sn_customerservice_commodity_code table. Please help

1 ACCEPTED SOLUTION

Divya Kandula
Kilo Guru

Creating Desc variable in both client script and Business rule caused the issue.

View solution in original post

4 REPLIES 4

AshishKM
Kilo Patron
Kilo Patron

Hi @Divya Kandula , 

What is the type of this field "u_commodity_code_hierarchy" single line/or/multi line.

Try with return Desc.toString(); in script include and test. 

 

-Thanks,
AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

It is a multi line string

return Desc.toString(); dint work

Divya Kandula
Kilo Guru

Creating Desc variable in both client script and Business rule caused the issue.