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

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.

 



Wowww Thankyou you very much @Taha Habib. I'm appreciating your Patience, hard work and logic. 

Thanks for the appreciation Venkat.