- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2023 08:20 AM - edited 03-03-2023 05:45 AM
I'm working on a catalog item that should automates the Newsletter Subscription.
Every new subscription request after it approves by the user's manager should automatically run a script in the workflow that will copy the highlighted field values as shown in RITM reference(Picture 1) and insert all of these to a new record in the target table(u_newsletter_subscription) form(Picture 2), then automatically submit the new record. The new record should be reflected in the Table list(Picture 3). Please see below script code that I put in the Run Script in the Workflow and it seems there are missing in my below script codes that it not working based on the expectation.
I would appreciate for any help. Thanks in advance.
//GlideRecord Query
var getTicket = new GlideRecord('sc_req_item');
getTicket.addQuery('number', variables.current.number);
getTicket.addQuery('requested_for', variables.current.requested_for);
getTicket.addQuery('requested_by', variables.current.requested_by);
getTicket.addQuery('end_date', variables.current.end_date);
getTicket.query();
if(getTicket.next())
{
var recinsert = new GlideRecord('u_newsletter_subscription');
recinsert.initialize();
recinsert.setValue('number', number);
recinsert.setValue('u_requested_for', getTicket.variables.requested_for);
recinsert.setValue('u_requested_by', getTicket.variables.requested_by);
recinsert.setValue('u_end_of_subscription', getTicket.variables.end_date);
recinsert.insert();
}
var createSub = new GlideRecord('u_newsletter_subscription');
createSub.initialize();
//fill out fields
createSub.u_requested_for = getTicket.current.variables.requested_for;
createSub.u_requested_by = getTicket.current.variables.requested_by;
createSub.u_end_ofsubscription = getTicket.current.variables.end_date;
createSub.insert();
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2023 06:04 AM - edited 03-03-2023 06:06 AM
Hi,
I found some errors errors in your script:
You are glide query RITM table, if you are using run script in workflow no need to glide query ritm, you can use current method to get variables like current.variables.requested_for.
Even in the addQuery method, you are adding parameter as
getTicket.addQuery('number', variables.current.number); its wrong it should be
getTicket.addQuery('number',current.variables.number); thats the reason you are not getting value while insert
Write a workflow run script like below to insert record in newsletter subscription table and it should work:
var createSub = new GlideRecord('u_newsletter_subscription');
createSub.initialize();
//fill out fields
createSub.u_requested_for =current.variables.requested_for;
createSub.u_requested_by =current.variables.requested_by;
createSub.u_end_ofsubscription = current.variables.end_date;
createSub.insert();
Please try and let me know.
Thanks,
Faizeal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2023 08:52 AM
Hi,
Did you get any error? Have you tried the same code in background script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2023 03:54 PM - edited 03-03-2023 05:47 AM
Hi Mohamed,
Thank you for your response. There is no error message. It just not copying the RITM variables value to the target table fields.
I ran the workflow but it is only inserting new record number on the table but it did not copy the current field values of the current RITM to requested for, requested by, end of subscription are still empty and the active value is still false. Please see Picture 5.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2023 06:04 AM - edited 03-03-2023 06:06 AM
Hi,
I found some errors errors in your script:
You are glide query RITM table, if you are using run script in workflow no need to glide query ritm, you can use current method to get variables like current.variables.requested_for.
Even in the addQuery method, you are adding parameter as
getTicket.addQuery('number', variables.current.number); its wrong it should be
getTicket.addQuery('number',current.variables.number); thats the reason you are not getting value while insert
Write a workflow run script like below to insert record in newsletter subscription table and it should work:
var createSub = new GlideRecord('u_newsletter_subscription');
createSub.initialize();
//fill out fields
createSub.u_requested_for =current.variables.requested_for;
createSub.u_requested_by =current.variables.requested_by;
createSub.u_end_ofsubscription = current.variables.end_date;
createSub.insert();
Please try and let me know.
Thanks,
Faizeal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2024 03:49 AM
Thank you! This helped me as I was using "current.variable.field_name", singular not plural, so "current.variableS.field_name" worked like a charm. :))
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */