Values are not getting populated on the form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 03:48 PM
Hello,
For an address validation on the form, if the zipcode is present in the location it will validated else it should be calling 3rd party for the validation, for the else in the flow able to get the response but on the it is clearing the value (object is getting returned).
Below is how I'm call the subflow in the script include :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 09:15 PM
Hi @is_12 , can you try to log outputs from the subflow itself?
Also try to log the JSON before returning in the else part.
Subflows has output defined right? (There is a comment showing - '// Current subflow has no outputs defined. '). I am assuming you defined it later and edited the script in script include.
Also, return the JSON in the try block.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 09:50 PM
Can you help me with the script please
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 09:57 PM
Sure, can you log the response coming back from subflow ? here - and let me know what you are getting in log? Also can you please share some screenshots of your subflow, and how outputs are mapped in subflow?
getLocationDetails: function() {
var zipcode = this.getParameter('sysparm_zipcode');
//var countryCode = this.getParameter('syspram_countryCode');
var city = this.getParameter('sysparm_city');
var state = this.getParameter('sysparm_state');
var country = this.getParameter('sysparm_country');
var countryCode = '';
var countryGR = new GlideRecord('core_country');
countryGR.addQuery('name', country);
countryGR.query();
if (countryGR.next()) {
countryCode = countryGR.getValue('iso3166_2'); // Assuming 'country_code' is the field name
}
var location = new GlideRecord('cmn_location');
location.addQuery('zip', zipcode);
location.query();
gs.info('I**bleep**ainsidefunction7');
gs.info('I**bleep**azipcode' + zipcode);
if (location.next()) {
gs.info('I**bleep**ainsidefunction8');
return JSON.stringify({
"country": location.getValue('country'),
"state": location.getValue('state'),
"city": location.getValue('city'),
"countryCode": countryCode
});
} else if (!location.next()) {
try {
var inputs = {};
inputs['state'] = state; // String
inputs['country'] = country; // String
inputs['countrycode'] = countryCode; // String
inputs['city'] = city; // String
inputs['zipcode'] = zipcode; // String
// Start Asynchronously: Uncomment to run in background. Code snippet will not have access to outputs.
// sn_fd.FlowAPI.getRunner().subflow('global.bt__call_the_mysite').inBackground().withInputs(inputs).run();
// Execute Synchronously: Run in foreground. Code snippet has access to outputs.
var result = sn_fd.FlowAPI.getRunner().subflow('x_bttm_bttsm_api.bt__call_the_mysite_v1').inForeground().withInputs(inputs).run();
var outputs = result.getOutputs();
var resppayload = outputs['resppayload'];
gs.log("Response from subflow - "+resppayload);
gs.log("country = "+resppayload.bestSuggested.country);
return JSON.stringify({
"country": resppayload.bestSuggested.country,
"countryCode": resppayload.bestSuggested.countryCode, // Now correctly pulling the country code
"state": resppayload.bestSuggested.county,
"city": resppayload.bestSuggested.town
});
// Current subflow has no outputs defined.
} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}
}
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 10:55 PM
did subflow run fine and give correct output?
what debugging did you perform?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader