how to check if all Record of Choice list has same value

aladpereira
Mega Expert

hi,

i am inserting Records into the Custom table based on the Assets selected in the List Collector from the Catalog form,   i have a choice list with choices, FIX, Replace, No action in the new table. The fulfiller will change the values of each records. Based on this field   we have below decison

1. If all records in the new table for that RITM   has NO action =   need to close RITM.

2. If any one   option is :FIX   = then need to create a incident

3. If any one option is :Replace   = then need to move forward with the RITM workflow which has catalog task.

4. if one is FIX and other is Replace = need to create incident and workflow.

How to achieve this in a best way?

4 REPLIES 4

Chuck Tomasi
Tera Patron

You could do this with a business rule. I don't know enough about your data structure (tables, fields, relationships, etc) to provide you with a specific script, but in general it would look something like this Anto... note this is not meant to be copy/pasted. It requires some mods and is intended to give you the general idea.



Standard disclaimer: The following code is untested, requires review and potential modifications.



(function () {  



        var no_action = 0;


        var fix = 0;


        var replace = 0;



      var rec = new GlideRecord('your_table');  


      rec.addQuery('field', 'value'); // filter all records down to just get the ones you are interested in where field=value


      rec.query();  


 


      while (rec.next()) {  


              if (rec.your_field == 'NO Action') {


                            ++no_action;


                  }


                  if (rec.your_field == ':Fix') {


                            ++fix;


                  }


                  if (rec.your_field == ':Replace') {


                            ++replace;


                  }



      }  



        // Now use if statements to determine what to do... Example


        if (fix > 0) {


                  var inc = new GlideRecord('incident');


                  inc.newRecord();


                  inc.short_description = 'Fix required');


                  inc.insert();


        }


})();  


ccajohnson
Kilo Sage

My guess is that you have a custom table that stores the assets and a decision for each asset, correct?


It is unclear what fields you have on your custom table. Hopefully you have a way of associating the custom table record with both the RITM and the Asset.


It is unclear how the fulfiller changes the values. Is this from each of the associated records? Is this through a related list?


My guess is that all of the Assets selected must be decided before anything else happens, correct?



Once these clarifications are made we should be able to focus our solution accordingly.


It is unclear what fields you have on your custom table. Hopefully you have a way of associating the custom table record with both the RITM and the Asset.


Answer : I have a choice list field and a Ritm field which provides relationship to RITM Table.



It is unclear how the fulfiller changes the values. Is this from each of the associated records? Is this through a related list?


Answer : Fulfiller open each records from Custom table which is in the Related list of RITM and upates the choice list.


Based upon what you have indicated and what I am guessing, here is a framework of what you can do:


*     You will need a Business Rule that runs after update to push the decision to the RITM record.


      -     This will be conditioned on if the choice field is populated and changes.


      -     Depending upon if you want the incidents to be generated at this time will need to be included in the script.


      -     This Business rule will also write to the Work notes of the RITM to indicate the decision made.


              (see below for reasoning behind writing to the work notes)


*     Since it appears that your decisions are based upon all of the generated records being answered, you should have a wait workflow action in your workflow.


      -     This wait will search the custom table to make sure that all decisions have been made.


      -     You will query the custom table on the RITM field


      -     You will also query the custom table for the choice field being not empty.


      -     If all related records have been answered, proceed.


      -     Since a wait workflow activity will only run when the record is updated, this is why you update the work notes. (I call it "touching" the record).


*     Once the workflow continues, you can then run a scripted If workflow activity to determine if all records are marked as 'NO action'.


      -     This will query the custom table on the RITM field.


      -     This will capture how many records have been found.


      -     This will iterate through all found records and increment a counter if the value of the Choice field is 'NO action'.


      -     If the counter and the number of records found match, then go down the path of closing the RITM.


      -     If the counter is less than the number of records found, then go down the path of continuing the RITM.


*     For those related records that have been marked as 'Replace', a scripted If workflow activite will be created.


      -     This will query the custom table on the RITM field.


      -     This will query for the choice field to be marked as 'Replace'.


      -     If any records are marked as 'Replace', go down the path of moveing forward with the RITM workflow which has catalog task.


*     Depending upon if you need to wait for the Incidents to be resolved will determine if a wait workflow action will be created.




My guess is that you understand how to write a business rule as well as create the different workflow activities. If you need further assistance, let us know.