- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-24-2022 07:44 AM - edited ‎12-26-2022 03:34 AM
In the pm_project related lists expense lines, and cost plans are there
On fm_expense_line record, there is 'cost plan' and 'task' reference fields
Generally cost plan field shows all cost plans.
If we take New expense line from pm_project related list, then task field is shown that project number like PRJ0002345. then Cost plans should show only related to PRJ0002345, if this was child project then show parent project cost plans
If it is Project task then it show parent Project costplans
if task field is empty or any other . So now we need all cost plans in that cost plan field.
I tried script include for reference qualifier, its not working please correct this
var CostPlanScriptInclude = Class.create();
CostPlanScriptInclude.prototype = {
initialize: function() {
},
getCostPlanReferenceQualifier: function(task) {
if (task.sys_class_name == 'pm_project' || task.sys_class_name == 'pm_project_task') {
return 'sub_tree_root=' + task;
} else {
return '';
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2022 02:16 AM
Hey Venkat,
I have added the required scripts in your instance. It's working as expectation.
I have used cost_plan, task. I have added the condition for pm_project, you can expand it as per your need.
Script Include:
var testdynamicfilter = Class.create();
testdynamicfilter.prototype = {
initialize: function() {},
refqual: function() {
var container = [];
var GrpU = current.task.number; // Task number we select on form
var classType = current.task.sys_class_name; // type of the task
// gs.info(" Number: "+ GrpU + "class:" + classType );
var testing; // variable to convert the glide to tostring
if(classType=="pm_project") // it will give only the related records if type = pm_project
{
var grpMember = new GlideRecord('cost_plan');
grpMember.addQuery('task.number', GrpU);
grpMember.query();
while (grpMember.next()) {
testing = grpMember.sys_id;
container.push(testing.toString());
//gs.info("toope " + grpMember.sys_id);
}
//gs.info("usermember: " + container.toString());
return 'sys_idIN' + container.toString();
}
else {
return 'all';
}
},
type: 'testdynamicfilter'
};
Dictionary Entry:
Result:
When task is empty or class type not pm_project, all records.
Else, it will display cost plans on the basis of tasks
Please mark this solution as correct and helpful. Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-26-2022 02:25 AM
Hey Venkat, the description seems incomplete "Get cost plans related to and" , related to what.? , it would be helpful, if you could elaborate a little more. Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-26-2022 03:35 AM
Hi @Taha Habib , I have updated description, please help me on this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-26-2022 12:39 PM
Hey Venkat,
Your requirement was very challenging, I did learnt a lot, while trying to get it right, so Thank you for the same. Also, I don't have right plugins so I was not able to replicate the exact thing, However, I have replicated it via Incident table, Sys_user, sys_group, and sys_user_grmember tables as an example.
Here in the below example I am applying dynamic qualifier on caller field and using assignment_group value to determine what goes into the caller field.
"If Assignment Group is "ITSM App-Dev" I will be able to get all users in the caller field who have the same assignment group, which will give me 4 results."
Else if Assignment Group is Anything other than ITSM App-Dev, I will be able to select all 600 users.
Note: To get all users, use: " return 'all'; " instead of " return '' " in your script.
Directory Entry for Caller Field: "Ps imp: Don't forget to tick Dynamic creation"
Dynamic Filter Option:
Script Include:
var testdynamicfilter = Class.create();
testdynamicfilter.prototype = {
initialize: function() {},
refqual: function() {
var userMember= [];
var GrpU = current.assignment_group.name;
gs.info(GrpU+"out");
var grpMember = new GlideRecord('sys_user_grmember');
grpMember.addQuery('group.name',GrpU );
grpMember.query();
while (grpMember.next()) {
userMember.push(grpMember.user.sys_id);
gs.info("toop"+ grpMember.user.sys_id);
}
gs.info("usermember:"+ userMember);
var re= userMember.replace("," , "" );
gs.info('sys_idIN' + userMember.toString());
if(GrpU=="ITSM App-Dev")
{
return 'sys_idIN' + userMember.toString();
}
else
{
return 'all';
}
},
type: 'testdynamicfilter'
};
Result:
Assignment group: Help Desk, all 622 records
When ITSM App dev only 4
I hope this information helps you, Also, if you find it helpful please mark this as helpful and accept the solution as correct. Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-26-2022 08:04 PM - edited ‎01-10-2023 12:29 AM
Hi @Taha Habib , Nice work on this, I think its little confuse for me. Please try my PDI with PPM installed.
Also giving link to that form. I will be thankful to you.
Your instance URL:https://dev129714.service-now.com
Username: admin
Current password: Mr-hsVFE7t^8
form link for cost plan and task fields
please let me know if you need any, Thankyou.