Last active
November 2, 2022 21:00
-
-
Save cmcdevitt/f91c2fdda70134f8f8a6ade6be35ba76 to your computer and use it in GitHub Desktop.
Populate Survey Questions via Script ServiceNow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| ServiceNow Vulnerability Response Exception Questionnaire | |
| 1. 'Assessment Instance Questions' [asmt_assessment_instance_question] table is populated with the Assessment Instance Questions | |
| 1.a. Keyfields: Source, Souce Table, Metric, Instance | |
| 2. The 'State Change Approval'[sn_vul_change_approval] table is populated with that Approval info AND | |
| 2.a Keyfield Questionnair [assessment_instance] | |
| 3. You need a way to associate the Assessment Instance Questions back to the triggering event | |
| 3.a Example: State Change Apprval KNOWS about the Assessment Instance via the Questionnair [assessment_instance] field | |
| 4. You will need to work "backwords" from the Assessment Instance Question table | |
| 4.a A Business Rule: "Before - Insert" :: Condition Source[source_id] is <sys_id> | |
| 4.b Note: The <sys_id> is the sys_id of the Survey found in Assessment Metric Type [asmt_metric_type] | |
| 4.c (BR) Test the Question to see if you need lookup the other parts: if(aiq.metric.getDisplayValue() == "Proceed"){...} | |
| 4.d (BR) If True :: Then You will need to Query the State Change Approval[sn_vul_change_approval] table for Questionnair [assessment_instance] | |
| 4.e Note: The Assessment Instance Questions -> Instance[instance] (Reference Assessment Instance[assessment_instance]) | |
| 4.f Note: State Change Approval fields: Questionnaire, Record Type, Record Reference | |
| 4.g (BR) Then you will need to Query the (VIT or VUL) table to get the information you need | |
| 4.h (BR) Then you can populate the Question: aiq.setValue('string_value', '1'); AND aiq.setValue('value', '1'); | |
| */ | |
| //Test Code | |
| //Populate Answers for an active assessment | |
| var qq = 'instance=1377b6a387be95102d0b422e0ebb3538';//AINST0010016 | |
| var aiq = new GlideRecord('asmt_assessment_instance_question'); | |
| aiq.addEncodedQuery(qq); | |
| aiq.query(); | |
| while(aiq.next()){ | |
| if(aiq.metric.getDisplayValue() == "Having Fun"){ | |
| aiq.setValue('string_value', 'Yes, I am still having fun++++'); | |
| aiq.update(); | |
| } | |
| if(aiq.metric.getDisplayValue() == "Proceed"){ | |
| aiq.setValue('string_value', '1'); | |
| aiq.setValue('value', '1'); | |
| aiq.update(); | |
| } | |
| } | |
| //To-Do Business Rule code.... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment