Showing posts with label map. Show all posts
Showing posts with label map. Show all posts

Sunday, 23 May 2021

SurveyMonkey Integration – Call External API from Automation Script | Maximo

In the continuation of my last post "integration with Survey Monkey through Zapier". 

I had another requirement to implement a customization to directly call the external API of Survey Monkey from Maximo.

Below are the 2 steps procedure, first is the list of APIs we are going to call in a sequence from Maximo Automation Script, and then the detail code I used.

Prerequisites: 

  • Survey Moneky Account, Token
  • Design Survey and enable "Embed First Question" in the Email
  • Create an Email collector 
  • Get the id of the newly created Email Collector


A. Three APIs we are going to call for this project from Automation Script: 

  1. https://api.surveymonkey.net/v3/collectors/{{COLLECTOR_ID}}/messages
    1. {
        "type": "invite",
        "subject": "Survey for the Ticket {{myextrafield}} {{CustomData1}}",
        "is_branding_enabled": true,
        "embed_first_question": true
      }
  2. https://api.surveymonkey.net/v3/collectors/{{COLLECTOR_ID}}/messages/{{MESSAGE_ID}}/recipients
    1. {     "email": "abdulqadeer.el@gmail.com",     "custom_fields": {    "1": "c1"},     "extra_fields": {     "myextrafield": "1234"   }    }
  3. https://api.surveymonkey.net/v3/collectors/{{COLLECTOR_ID}}/messages/{{MESSAGE_ID}}/send
    1. { }

B. Jython code can be implemented on any object, for testing I am using SR object before-save trigger. 

Sunday, 14 June 2020

List of Items as Parameters of a Function, Map() | Python

Map isn't pythonic, use list instead. 

map(func, iterable)

func : It is a function to which map passes each element of given iterable.
iter : It is a list which is to be mapped( list of parameters to be passed to func).

lets say:
>>> func add(a):
>>>     return a+5;
>>> print add(2)    // 2 as parameter, it will return 2+5=77

//lets give a list of parameters instead of only 1 param

>>> myList = (2,6,7,1)

//first lets do the same with for loop.
>>> for i in number:
...     print add(i);...
96

// lets do the same with list.
func add(a):
    returnn a+5;
myList = (2,6,7,1);
// all items of list will be the parameter for the function add().
>>> print map(add, myList)
[6, 10, 11, 5]