Create a Global Function for salesMLQuerySimilarRecords API
Here's how you create a global function for the salesMLQuerySimilarRecords API:
- Continue in the active sandbox and navigate to .
- Click the global function icon.
- On the Create Global Function page, enter a Function Name.
For example, invokeSalesMLSimilarRecordsQueryAPI.
Ensure that you use same global function name in the Groovy for the formulae type field.
- Select String for Returns.
- Add these parameters:
- Name: useCaseCode Type: String.
- Name: objectPKName Type: String.
- Name: recordPKValue Type: Long (Integer).
- Add this Groovy code in the Edit Script field:
def inputMap = [:]; def accountNames = ""; def debugLog = ""; if(recordPKValue != null) { try { debugLog += "Primary Key:"+recordPKValue; def wsRequest = adf.webServices.salesMLQueryAPISimilarRecords; def httpHeaders = ['Content-Type': 'application/json', 'Accept-Encoding': 'text/plain'] wsRequest.requestHTTPHeaders = httpHeaders; inputMap.put("UseCaseCode", useCaseCode); inputMap.put("QueryMetadata", "whereClause:".concat(objectPKName).concat("=").concat(recordPKValue.toString()).concat(";numberOfRows:5")); def partyIds = ""; debugLog += "GOING TO INVOKE SALESML API: "; def wsResponse = wsRequest.POST(inputMap); debugLog += "SALESML API INVOKED: "; for(similarAccount in wsResponse) { if(partyIds == "") { partyIds += similarAccount.PARTYID; } else { partyIds += ","+similarAccount.PARTYID; } } if(partyIds != "") { debugLog += "START ACCOUNTS GET PREP: "; def wsRequest2 = adf.webServices.Acconts_GET; def httpHeaders2 = ['REST-Framework-Version': '2']; wsRequest2.requestHTTPHeaders = httpHeaders2; def queryParams = ['q':'PartyId IN ('+partyIds+')']; wsRequest2.dynamicQueryParams = queryParams; debugLog += "GOING TO INVOKE ACCOUNTS GET: "; def accounts = wsRequest2.GET(); debugLog += "INVOKED ACCOUNTS GET: "; def count = 0; for(account in accounts.items) { if(count == 0) { accountNames += account.OrganizationName; } else { if(count<5){ accountNames += ",\n"+account.OrganizationName; } else { break; } } count++; } } } catch (e) { debugLog += e.getMessage(); accountNames = debugLog; } } else { accountNames = "Not Available"; } if(accountNames == "") { accountNames = "Not Available"; } return accountNames;
- Click Validate.
- Click Save and Close.The Groovy may show some warnings. Ignore those warnings and click Yes to save the script.