{"ScriptPreparationCode":"function validatePersonSome(person, isCmsgOrgs, selectedOrgs) {\r\n if (isCmsgOrgs) {\r\n // If a person has service_groups it will check them against the org SERVICE_GROUP_IDS, if a match is found that person will be selectable\r\n if (person.service_groups.length) { // eslint-disable-line mp-camelcase\r\n return person.service_groups.some(function(service_group) { // eslint-disable-line mp-camelcase\r\n return selectedOrgs.some(function(org) {\r\n return org.SERVICE_GROUP_IDS.some(function(org_service_group) { // eslint-disable-line mp-camelcase\r\n return org_service_group.SERVICE_GROUP_ID === service_group.id; // eslint-disable-line mp-camelcase\r\n });\r\n });\r\n });\r\n } else {\r\n return false;\r\n }\r\n }\r\n // If no orgs contain SERVICE_GROUP_IDS, only those persons with no service_groups will be selectable\r\n else {\r\n return person.service_groups.length === 0;\r\n }\r\n}\r\n\r\nfunction validatePersonLoop(person, hasCmsgOrgs, selectedOrgs) {\r\n var isValid = false;\r\n\r\n if (hasCmsgOrgs) {\r\n // If a person has service_groups it will check them against the org SERVICE_GROUP_IDS, if a match is found that person will be selectable\r\n if (person.service_groups.length) {\r\n var orgServiceGroupIds = {};\r\n var org;\r\n\r\n for (var i = 0; i \u003C selectedOrgs.length; i\u002B\u002B) {\r\n org = selectedOrgs[i];\r\n for (var j = 0; j \u003C org.SERVICE_GROUP_IDS.length; j\u002B\u002B) {\r\n orgServiceGroupIds[org.SERVICE_GROUP_IDS[j].SERVICE_GROUP_ID] = true;\r\n }\r\n }\r\n\r\n for (var i = 0; i \u003C person.service_groups.length; i\u002B\u002B) {\r\n if (orgServiceGroupIds[person.service_groups[i].id]) {\r\n isValid = true;\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n // If no orgs contain SERVICE_GROUP_IDS, only those persons with no service_groups will be selectable\r\n else {\r\n isValid = person.service_groups.length === 0;\r\n }\r\n\r\n return isValid;\r\n}\r\n\r\nvar person = {};\r\nperson.service_groups = [];\r\nfor (var i = 0; i \u003C 1000; i\u002B\u002B) {\r\n person.service_groups.push({\r\n id: i\r\n });\r\n}\r\n\r\n\r\nvar selectedOrgs = [];\r\nselectedOrgs.push({\r\n\t\u0022ORGANIZATION_ID\u0022: \u002212345\u0022,\r\n \t\u0022ORG_NAME\u0022: \u0022some_name\u0022,\r\n \t\u0022SERVICE_GROUP_IDS\u0022: [{\r\n service_group_id: 1\r\n }]\r\n});\r\n\r\n\r\n","TestCases":[{"Name":"For Loop","Code":"\r\nvalidatePersonLoop(person, true, selectedOrgs);","IsDeferred":false},{"Name":"Some","Code":"\r\nvalidatePersonSome(person, true, selectedOrgs);","IsDeferred":false}]}