- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2023 02:20 AM
Hi, I have a table A and I query all the reocrds and I have 2 fields in the table that I need to get for example "numberofdays1" and "numberofdays2".
Once I get that I add the "numberofdays1" and "numberofdays2". But once I get this "totalnumberofdays", I need to query the same table A and find a field called "Enddate"(which is a date field) and add the following condition:
get all records where the "Enddate" is within the "totalnumberofdays" .
Now I am confused as to how do I code this.
var grA = new GlideRecord("A");
grA.Query();
var totalnumberofdays;
while (grA .next()){
totalnumberofdays= grA .numberofdays1+ grA .numberofdays1;
}
Now inside this loop, how do I query the same table "A", and find all the records where the "Enddate" is within a "totalnumberfdays"
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2023 06:29 AM
from your question I did not get how you are doing this I am not sure, if you are doing this using Business Rule, I will request you to create 2 separate functions in Script Include and call one by one here. also you can provide input query parameter to script include too.
Call the First Function which will give you the counting of your total number of days. same thing doing in business rule is also Ok. just pass this result as input query to script include.
var grQuery = new GlideRecord("A");
grQuery .query();
var days = 0;
while (grQuery .next()) {{
days += parseInt(grA.numberofdays1) + parseInt(grA.numberofdays2);
}
break;
}
Now you just have to pass this result to your script include, in which you can write below code
reassignWork: function(myDay) {
var aTable = new GlideRecord('atable');
atable.EncodedQuery("");
aTable.query();
if (aTable.next()) {
//your work
return variable_name
}
},
refer below screenshots and links how you can call script include to Business Rule.
Mark my Response as Correct or Helpful, if you find it Appropriate.
Gaurav Shirsat : ServiceNow Community MVP 2022
https://www.linkedin.com/in/gauravshirsat/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2023 09:35 AM
Another requirement in the job above. I have a table which has 2 integerfields which is Numberofdates1 and NumberofDates2. I also have the enddate(date field). I need to send the following notifications based on the conditions
1 . Notification1 -> gets triggered when end date(Dec 31,2023) is within Numberofdates1 + Numberofdates2. So if Numberofdates1 is 20 and Numberofdates2 is 30 , I need to find if the total is within the totalnumberofdates (50 days)
2. Notification2 -> gets triggered once every month till end date(until Nov 30,2023)
3. Notification 3-> gets triggered once every week from Nov 30 to Dec 30
If the receiver of the email responds and a request is created then no need to send the subsequent notifications.
I think I may need some help with scripting the condition for Notification2 and Notification 3.
Any suggestions?
Thanks in advance
3.