The CreatorCon Call for Content is officially open! Get started here.

Get cost plans related to project or project task, otherwise I need all cost plans

venkat Y
Tera Contributor

com2eee.JPG

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 '';
    }
  }
}

 

 

1 ACCEPTED SOLUTION

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:

 

TahaHabib_0-1672135878220.png

 

Result:

When task is empty or class type not pm_project, all records.

TahaHabib_1-1672135983279.png

 

Else, it will display cost plans on the basis of tasks

 

TahaHabib_2-1672136129461.png

 

Please mark this solution as correct and helpful. Thank you.

 



View solution in original post

7 REPLIES 7

Taha Habib
Tera Guru

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. 

Hi @Taha Habib , I have updated description, please help me on this

Taha Habib
Tera Guru

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"

TahaHabib_0-1672086691498.png

 

Dynamic Filter Option:

 

TahaHabib_2-1672086825221.png


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

TahaHabib_3-1672086997674.png

 

When ITSM App dev only 4

 

TahaHabib_4-1672087074170.png

 

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.

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

https://dev129714.service-now.com/nav_to.do?uri=fm_expense_line.do?sys_id=ba62b6c147002110a500da9743....

 

please let me know if you need any, Thankyou.