- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2023 11:56 AM
Hi,
I am trying to populate the 'fiscal period' on Requested allocation based on start date and end date through before Insert/Update BR but it's not working. This BR is not running at all. Can someone please help me with this ?
Requested allocation record gets created when we submit resource plan.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2023 05:28 AM
This is likely related to the timezone offset pointed out below. To work with the other field formats, the script would look like this:
(function executeRule(current, previous /*null when async*/ ) {
var AllocStartDate = new GlideDateTime(current.start_date)
AllocStartDate = AllocStartDate.getDate().toString().replace("-","") + "T000000";
var AllocEndDate = new GlideDateTime(current.end_date)
AllocEndDate = AllocEndDate.getDate().toString().replace("-","") + "T235959";
var fsp = new GlideRecord('fiscal_period');
fsp.addEncodedQuery("start_date_time<=" + AllocStartDate + "^end_date_time>=" + AllocEndDate + "^fiscal_type=quarter");
fsp.query();
gs.addInfoMessage("Allocation Date Range " + AllocStartDate + ' - ' + AllocEndDate)
if (fsp.next()) {
current.u_fiscal_period = fsp.sys_id;
gs.addInfoMessage("Inside if : " + current.number);
} else {
gs.addInfoMessage("Inside else : " + current.number + " : " + current.start_date + " : " + current.end_date);
//gs.addErrorMessage("Due to allocation mismatch, could not populate fiscal period.");
}
})(current, previous);
If this still isn't working for all fiscal periods in your environment, I'll check it out in your PDI and likely go back to the other date fields with a timezone offset, if that's the issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2023 04:38 PM
Thanks Brad. I see and it's logical because of that SC, any other BR is not triggering. But my worry is if this is OOB functionality and if I stop this, what would be the underlying impact ? Definity I need to test this thoroughly I go with this route.
Is there any other way apart from commenting this line and write some independent script component which will handle my requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2023 05:11 AM
You can create another Business Rule on the resource_plan table after Insert with this script to force an update to the requested_allocation record, so that your other before Update Business Rule will trigger, then you don't need to modify any out of box scripts.
(function executeRule(current, previous /*null when async*/) {
var ra = new GlideRecord('requested_allocation');
ra.addQuery('resource_plan', current.sys_id);
ra.query();
if (ra.next) {
ra.update();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2023 05:08 PM
HI Brad,
As suggested, I have added another after Insert BR on Resource_plan table and strange thing is this BR is running and executing on the record which is very last in the requested allocation and it's not tied with any of the resource plan. It's running/may be causing to insert a blank requested allocation record in the system.
When to Run : After Insert
Order : 100
Table : Resource_plan
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var ra = new GlideRecord('requested_allocation');
ra.addQuery('resource_plan', current.sys_id);
ra.query();
if (ra.next) {
ra.update();
gs.log("Resource Plan Test : " + ra.number);
gs.addInfoMessage("New BR Inside");
}
})(current, previous);
When I check the log stmt, I found below for requested allocation for my multiple testresource plan records.
Resource Plan Test : REQAL0006484 |
Resource Plan Test : REQAL0006494 |
Resource Plan Test : REQAL0006504 |
All these 3 records are completely blank and not tied with any of the resource_plan in the system.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2023 05:13 PM
This is my before insert/update BR on requested allocation table to populate fiscal period.
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var AllocStartDate = new GlideDateTime(current.start_date) + " 00:00:00";
var AllocEndDate = new GlideDateTime(current.end_date) + " 23:59:59";
var fsp = new GlideRecord('fiscal_period');
fsp.addEncodedQuery("fiscal_start_date_time<=" + AllocStartDate + "^fiscal_end_date_time>=" + AllocEndDate + "^fiscal_type=445period");
fsp.query();
if (fsp.next()) {
current.u_fiscal_period = fsp.sys_id;
gs.addInfoMessage("Inside if : " + current.number);
} else {
current.u_fiscal_period = fsp.sys_id;
gs.addInfoMessage("Inside else : " + current.number + " : " + current.start_date + " : " + current.end_date);
//gs.addErrorMessage("Due to allocation mismatch, could not populate fiscal period.");
}
})(current, previous);
When : Before Insert/update
Order : 100
Table : requested_allocation
This is the info message from script : "Inside else : REQAL0006524 : :"
As mentioned earlier REQAL0006524 is completely blank record and not tied with any of the resource plan in the system.
What could be the cause ? Do you think here should I change the BR order ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2023 05:25 PM
When I started debugging I found below in the session logs.
Update ReqAllocation is the BR which you suggested on resource_plan table
Populate Fiscal Period - ReqAlloc is my BR on requested_allocation table to populate fiscal period.
17:10:08.74 Finished executing after update business rules on resource_plan: RPLN0001534 after engines (order >=1000)
17:10:08.76 Global <== 'Create Requested Allocations' on resource_plan: RPLN0001534
17:10:08.76 Global ==> 'Update ReqAllocation' on resource_plan: RPLN0001534
17:10:08.84 Execute before insert business rules on requested_allocation: REQAL0006524 before engines (order <1000)
17:10:08.85 Global === Skipping 'Prevent overlapping allocations' on requested_allocation: REQAL0006524; condition not satisfied: Filter Condition: start_dateVALCHANGES^ORend_dateVALCHANGES^EQ
17:10:08.86 Global === Skipping 'SyncManDaysFteCapacityRequestedHours' on requested_allocation: REQAL0006524; condition not satisfied: Filter Condition: resource_plan.plan_type=task^fteVALCHANGES^ORman_daysVALCHANGES^ORrequested_hoursVALCHANGES^NQresource_plan.plan_type=operational_work^percent_capacityVALCHANGES^ORrequested_hoursVALCHANGES^EQ
17:10:08.86 Global ==> 'Populate Fiscal Period - ReqAlloc' on requested_allocation: REQAL0006524
17:10:08.91 Global <== 'Populate Fiscal Period - ReqAlloc' on requested_allocation: REQAL0006524
17:10:08.91 Finished executing before insert business rules on requested_allocation: REQAL0006524 before engines (order <1000)
17:10:08.97 Execute after insert business rules on requested_allocation: REQAL0006524 after engines (order >=1000)