{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":26860,"path":"it-business-management/goal-framework/target-automation-script-benefit-plans.md","title":"Target automation script for benefit plans","bundle":null,"doc_type":null,"release":"australia","body":"\n# Target automation script for benefit plans\n\nUse the predefined Benefit Plans script as a target source to automate the actual value of your targets from the benefit plans of relevant work items.\n\nUse the following predefined benefit plans script to configure the target source for your targets. The script fetches the required data for monetary or non-monetary benefit plans and updates the actual value for the target. You can use this script as is or you can also modify it according to your requirement. You can also create context variables and configure them for this target source \\(Benefit Plans\\).\n\n```\nresult = '';\nvar benefitPlans = new GlideRecord(sn_gfa.GFAdvancedConstants.BENEFIT_PLAN_TABLE);\nbenefitPlans.addQuery('sys_id', 'IN', benefit_plan);\nbenefitPlans.query();\n\nvar nonMonetaryBenefitSum = 0;\nvar monetaryBenefitSum = 0;\nvar hasMonetary = false;\nvar hasNonMonetary = false;\nwhile (benefitPlans.next() && !(hasMonetary && hasNonMonetary)) {\n    if (!gs.nil(benefitPlans.getValue('currency'))) {\n        monetaryBenefitSum += parseInt(benefitPlans.getValue('actual_benefit'));\n        hasMonetary = true;\n    } else {\n        nonMonetaryBenefitSum += parseInt(benefitPlans.getValue('nm_actual_benefit'));\n        hasNonMonetary = true;\n    }\n}\n\nif (hasMonetary && hasNonMonetary)\n    gs.addErrorMessage(gs.getMessage('The Benefit Plan list can contain either monetary or non-monetary benefit plans.'));\nelse\n    result = hasMonetary ? monetaryBenefitSum : nonMonetaryBenefitSum;\n```\n\n**Parent Topic:**[Goal Framework and Goal Framework for SPM reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/it-business-management/goal-framework/goal-framework-reference.md)\n\n"}}