Sample script file for Custom Trigger in Change module

    #Example to assign CAB members based on the value of impact configured in change.

     #if impact is High then emergency CAB members will be assigned. Else normal CAB members will be assigned to the change.

    import sys

    import json

    import urllib

     

    file_Path = sys.argv[1]

    with open(file_Path) as data_file:

        data = json.load(data_file)

     

    #fetch the impact value from the change JSON.

    #JSON Format in change will be {'INPUT_DATA':{"entity": "change","login_name": "menders","entity_data": {..},"entity_diff_data": {...}}

    inputData = data['INPUT_DATA']

    changeData = inputData['entity_data']

    impact = changeData['impact']

    impactValue = impact['name']

     

    #configure emergency CAB for impact value "High".

    if impactValue == 'High':

        returnJSON = {

        #message : value to be shown in change history

            'message': 'Adding Emergency CAB members through Custom Trigger',

            'operations': [{

                #operation_name denotes the operation to be done through trigger ,currently UPDATE_ROLES is only supported.

                'operation_name': 'UPDATE_ROLES',

                'input_data': {

                    'change': {

                        'roles': [{

                            #replace with the Role ID to be updated

                            'id': 5, 

                            #replace with the role Name to be updated .

                            'name': 'CAB'

                            #users can be added/updated to change roles using either emailid or user id .

                            'users': [{

                                # emailid of the user to be configured

                               'email': 'heather@xyz.com', 

                               #name of the user corresponding to the email id

                               'name': 'Heather Graham' 

                            }, {

                                #ID of user to be configured

                                'id': 3,

                                #name of the user corresponding to the ID

                                'name': 'Shawn Adams'

                            }]

                        }]

                    }

                }

            }]

        }

        #configure normal CAB for other values of impact

         else :

        returnJSON = {

         #message -value to be shown in change history

            'message': 'Adding Normal CAB members through Custom Trigger',

             #operation_name denotes the operation to be done through trigger, currently UPDATE_ROLES is only supported.

            'operations': [{

                'operation_name': 'UPDATE_ROLES',

                'input_data': {

                    'change': {

                         'roles': [{

                            #replace with the Role ID to be updated

                            'id': 5, 

                            #replace with the role Name to be updated .

                            'name': 'CAB'

                            #users can be added/updated to change roles using either emailid or user id .

                            'users': [{

                                # emailid of the user to be configured

                               'email': 'john@xyz.com', 

                               #name of the user corresponding to the email id

                               'name': 'John' 

                            }, {

                                #ID of user to be configured

                                'id': 4,

                                #name of the user corresponding to the ID

                                'name': 'Howard stern'

                            }]

                        }]

                    }

                }

            }]

        }

    print(json.dumps(returnJSON))

    Copyright © 2017, ZOHO Corp. All Rights Reserved.