- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2025 12:44 AM
Hello All,
I am working on a requirement where on a record producer the requirement is to auto populate a field where there is only one record referenced within it. I have tried using a catalog script for this, but it is not working.
Anyone have a script or a method where they have this working? Or knows how to do it?
Here is my current code.
Catalog client script
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2025 04:51 AM
are you testing with admin or non-admin?
if non-admin then ensure user has read access on table "sn_install_base_sold_product"
In my instance there are lot of records and I tested with setLimit(1) and it worked.
Output: It gave me 1 record for me correctly
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2025 02:34 AM
Hi @Luke James , I tried the same lines of code with just table change in my PDI,it works fine. The value is auto populating as expected.
Are you sure the variable name that you are trying to populate is 'sold_product'
Also are there 'active' true records in the table - 'sn_install_base_sold_product'
Also, here - which one is getting printed - if block or else block?
console.log(':inbox_tray: GlideAjax response for sold_product: ', answer);
if (answer) {
g_form.setValue('sold_product', answer);
console.log(':white_heavy_check_mark: Auto-filled sold_product with: ' + answer);
} else {
console.log(':cross_mark: No single product found – leaving sold_product blank.');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2025 03:22 AM
Hi @GopikaP ,
Thanks for your response. I checked the logs and i'm getting this response
🔄 Checking for single matching sold_product...
VM112322:10 📥 GlideAjax response for sold_product: null
VM112322:15 ❌ No single product found – leaving sold_product blank.
Just to show you as well, there is only one sold product available in this list for the account and contact that is populated. But it is not automatically populating, any ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2025 02:50 AM
Update as this in default value of that variable and it will work and no client script, script include required
there is no active field on that table "sn_install_base_sold_product"
I believe you want State=Active
javascript: var recordSysId = '';
var gr = new GlideRecord('sn_install_base_sold_product');
gr.addEncodedQuery('state=active');
gr.query();
var count = gr.getRowCount();
if (count == 1 && gr.next()) {
recordSysId = gr.getUniqueValue();
}
recordSysId;
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2025 03:23 AM
Hi @Ankur Bawiskar ,
Thanks very much for your response. I did try this, but it did not work. Did you mean paste your script into the default value of the field?
Kind Regards,
Luke