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

Getting Error Match not found, reset to original and not able to save the records,, Kindly help

AnjuG
Tera Contributor

Client Script 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading ||  newValue === '') {
        return;
    }
    alert("Client Script started");
    var street = g_form.getValue('street'); // will return sys_id
     if (!street) {
        alert("No street selected. Please select a valid street.");
        return;
    }
    alert("SysId " + street);
    var ga = new GlideAjax('CityAutoPopulate');
    ga.addParam('sysparm_name', 'PopulateCity');
    ga.addParam('sysparm_value', street); // Whatever street we select on...  its pass on the server side
    ga.getXML(getResponse);
    function getResponse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
                   var test = answer.split(',');
            g_form.setValue('city', test[0]);
            g_form.setValue('postal_code', test[1]);
                  alert("City set to: " + answer);
     }
    //Type appropriate comment here, and begin script below
}
  AND
Script Include 
var CityAutoPopulate = Class.create();
CityAutoPopulate.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    PopulateCity: function() {
        var sysIdOfStreet = this.getParameter('sysparm_value'); // Will return sys_id
        var gr = new GlideRecord('cmn_location');
        gr.addQuery('sys_id', sysIdOfStreet);
        gr.query();
        if (gr.next()) {
            return gr.city + ',' + gr.zip;
        } else {
            return ''; // Return empty string if no match is found
        }
    },
    type: 'CityAutoPopulate'
});
2 REPLIES 2

KarthikB9365919
Tera Contributor

Hi @AnjuG 

I think you can use JSON.stringify() while returning the values from script include and everything else seems fine.

Sandeep Rajput
Tera Patron
Tera Patron

@AnjuG The code looks fine, did you check if there is a street associated with the sys_id you are passing from the client side?