salesMLQuerySimilarRecords APIのグローバル関数の作成
salesMLQuerySimilarRecords APIのグローバル関数を作成する方法を次に示します。
- アクティブなサンドボックスで続行し、 にナビゲートします。
- グローバル関数アイコンをクリックします。
- 「グローバル関数の作成」ページで、関数名を入力します。 たとえば、invokeSalesMLSimilarRecordsQueryAPIのようにします。
Groovyで同じグローバル関数名を式タイプ・フィールドに使用してください。
- 「戻り値」に「String」を選択します。
- 次のパラメータを追加します。
- 名前: useCaseCode 型: String。
- 名前: objectPKName 型: String。
- 名前: recordPKValue 型: Long(整数)。
- 次のGroovyコードを「スクリプトの編集」フィールドに追加します。
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;
- 「検証」をクリックします。
- 「保存して閉じる」をクリックします。Groovyに警告が表示される場合があります。 これらの警告を無視し、「はい」をクリックしてスクリプトを保存します。