How to set a Idea record to Closed or Completed?

Kumari Divya
Giga Guru

Hello -  When we submitted the idea and it is in submitted/approved state,  when demand is created with the Create task Ui action then Idea should  in- In Backlog state until we closed the demand and when we Closed complete the Demand then idea also in closed complete State.

I wrote 1 before BR on the Demand table with the below script with when to run as state changes but it is not working,

 

(function executeRule(current, previous /*null when async*/ ) {
    //var parentNumber = current.number.toString();
    var ideaState = new GlideRecord('im_idea_core');
    ideaState.addQuery('task', sys_id);
    ideaState.query();
    if(ideaState.next()) {

        if (current.state == '0' || current.state == '4' || current.state == '1' || current.state == '2' || current.state == '3' || current.state == '5' || current.state == '6') {
            ideaState.state = '3';
            ideaState.update();
        } else if (demand.state == '7') {
            ideaState.state = '6';
            ideaState.update();
        }
    }
})(current, previous);
 
Note:same i need to create for Project as well.
Thanks in advance
2 ACCEPTED SOLUTIONS

Krushna R Birla
Kilo Sage

Hi @Kumari Divya 

 

Can you change BR from before to after and in condition add "state changes to close complete". Also add below script in your script tab

 

(function executeRule(current, previous /*null when async*/ ) {
//var parentNumber = current.number.toString();
var ideaState = new GlideRecord('im_idea_core');
ideaState.addQuery('task', current.sys_id); //Chech backend value of task here and check if demand is there
ideaState.query();
if (ideaState.next()) {

if (current.state == '0' || current.state == '4' || current.state == '1' || current.state == '2' || current.state == '3' || current.state == '5' || current.state == '6') {
ideaState.state = '3';
ideaState.update();
} else if (current.state == '7') {
ideaState.state = '6';
ideaState.update();
}
}
})(current, previous);
 

This will definitely helps you to resolved your issue. Let me know in case you need to understand the flow or you can DM on LinkedIn.

 

If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.

 

Best Regards,
Krushna Birla

View solution in original post

Hi @Krushna R Birla 

i created 1 after update  BR  on condition as state changes on Demand table with below script and updating the state now.

   (function executeRule(current, previous /*null when async*/ ) {
       //var parentNumber = current.number.toString();
       var ideaState = new GlideRecord('idea');
       ideaState.addEncodedQuery('taskSTARTSWITHDMND'); // fetching the idea with task records as demand
       ideaState.addQuery('task', current.sys_id);
       ideaState.query();
       if (ideaState.next()) {
              //if demand state is draft,Submitted,Screening and approved
           if (current.state == '1' || current.state == '2' || current.state == '3' || current.state == '8') {
               ideaState.setValue('state', 2);  //setting idea state as in backlog
               ideaState.update();
           } else if (current.state == '9') {
               ideaState.setValue('close_notes', "Closing idea as the corresponding demand is closed");
               ideaState.setValue('state', 3);
               ideaState.update();
           }
       }
   })(current, previous);
 
Thanks 

View solution in original post

5 REPLIES 5

Krushna R Birla
Kilo Sage

Hi @Kumari Divya 

 

You need to modify your query condition as,

ideaState.addQuery('task', current.sys_id);
 

This will definitely helps you to resolved your issue. Let me know in case you need to understand the flow or you can DM on LinkedIn.

 

If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.

 

Best Regards,
Krushna Birla

@Krushna R Birla 

Its not working.

 

Thanks 

Krushna R Birla
Kilo Sage

Hi @Kumari Divya 

 

Can you change BR from before to after and in condition add "state changes to close complete". Also add below script in your script tab

 

(function executeRule(current, previous /*null when async*/ ) {
//var parentNumber = current.number.toString();
var ideaState = new GlideRecord('im_idea_core');
ideaState.addQuery('task', current.sys_id); //Chech backend value of task here and check if demand is there
ideaState.query();
if (ideaState.next()) {

if (current.state == '0' || current.state == '4' || current.state == '1' || current.state == '2' || current.state == '3' || current.state == '5' || current.state == '6') {
ideaState.state = '3';
ideaState.update();
} else if (current.state == '7') {
ideaState.state = '6';
ideaState.update();
}
}
})(current, previous);
 

This will definitely helps you to resolved your issue. Let me know in case you need to understand the flow or you can DM on LinkedIn.

 

If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.

 

Best Regards,
Krushna Birla

Hi @Krushna R Birla 

i created 1 after update  BR  on condition as state changes on Demand table with below script and updating the state now.

   (function executeRule(current, previous /*null when async*/ ) {
       //var parentNumber = current.number.toString();
       var ideaState = new GlideRecord('idea');
       ideaState.addEncodedQuery('taskSTARTSWITHDMND'); // fetching the idea with task records as demand
       ideaState.addQuery('task', current.sys_id);
       ideaState.query();
       if (ideaState.next()) {
              //if demand state is draft,Submitted,Screening and approved
           if (current.state == '1' || current.state == '2' || current.state == '3' || current.state == '8') {
               ideaState.setValue('state', 2);  //setting idea state as in backlog
               ideaState.update();
           } else if (current.state == '9') {
               ideaState.setValue('close_notes', "Closing idea as the corresponding demand is closed");
               ideaState.setValue('state', 3);
               ideaState.update();
           }
       }
   })(current, previous);
 
Thanks