Acumatica REST API - Create activity linked to customer - json

I am trying to programmatically add an activity to a customer entity. I can create both a customer and a note using the API with a PUT, but I cannot figure out how to relate the activity to the customer. I viewed the JSON definition using Postman, but didn't see anything that made sense for relating it to another entity. I tried adding RelatedEntityDescription, but that unsurprisingly did not work.
Here is my JSON body for the PUT (it works but creates an un-linked activity)
{
"Body": {
"value": "message text"
},
"Date": {
"value": "2020-04-22T15:28:00.99-05:00"
},
"Summary": {
"value": "Test message"
}
}
What do I need to add to link it to my customer?

Good day Sreimer
The Table you should be saving to is Note.
It links on BAccount.NoteID and Note.NoteID.
An easy way to test this is to create and save a note on a customers and look for it in Note:
select *
from Note
where NoteText like '%test%';

You just need to specify the RelatedEntityType and RelatedEntityNoteID in your request
{
"Body": {},
"Date": {
"value": "2021-01-06T14:42:03.837-08:00"
},
"RelatedEntityNoteID": {
"value": "01a0c017-df7f-ea11-8175-b9d61cb73193"
},
"RelatedEntityType": {
"value": "PX.Objects.AR.Customer"
},
"Summary": {
"value": "Test Activity 4"
},
"Type" : {
"value" : "M"
}
}

Related

Azure Data Factory - Teams Message Card including variable results

I have a teams message card that I post using a web activity.
Currently, I do a lookup to determine whether or not I post the results, those results are stored in a variable, like so;
I want to include the results held in "Set variable" within my teams message, this will output the following as an array;
Using the web body, in expression builder, how can I include the values stored in the variable within my message, here is what I have generated so far;
{
"#type": "MessageCard",
"#context": "https://schema.org/extensions",
"summary": "This is the summary property",
"themeColor": "800000",
"sections": [
{
"heroImage": {
"image": "https://messagecardplayground.azurewebsites.net/assets/FlowLogo.png"
}
},
{
"startGroup": true,
"title": "**Checks - Requires Investigation**",
"facts": [
{
"name": "Date submitted:",
"value": "06/27/2017, 2:44 PM"
},
{
"name": "Details:",
"value": "The validation checks are hilighted below; "
},
{
"name": "Results:",
"value": "Include the output here"
},
{
"name": "Support Document:",
"value": "[Click here](https://dev.azure.com/supportDocument)"
}
]
}
]
}
You can use String interpolation to include the value of your variable (array). Please look at the following demonstration:
I have used a fake API in my web activity where I use PUT method. The following is the request body that is needed to be passed to the API.
{
"name": "morpheus",
"job": "leader"
}
Instead of using static data, if I want to use dynamic content (lets say, for 'name') i.e., use the result of my variable in the web body, we can do it in the following way. In the following, the variable req_name has value morpheus.
{
"name": "#{variables('req_name')}",
"job": "leader"
}
Now since you have the required result, which should be used in web body, stored in your variable, you can change your body as follows in the expression builder:
{
"#type": "MessageCard",
"#context": "https://schema.org/extensions",
"summary": "This is the summary property",
"themeColor": "800000",
"sections": [
{
"heroImage": {
"image": "https://messagecardplayground.azurewebsites.net/assets/FlowLogo.png"
}
},
{
"startGroup": true,
"title": "**Checks - Requires Investigation**",
"facts": [
{
"name": "Date submitted:",
"value": "06/27/2017, 2:44 PM"
},
{
"name": "Details:",
"value": "The validation checks are hilighted below; "
},
{
"name": "Results:",
"value": "#{variables('<your_variable_name>')}"
},
{
"name": "Support Document:",
"value": "[Click here](https://dev.azure.com/supportDocument)"
}
]
}
]
}
NOTE:
You can always check the debug input to check whether the body you are passing is the correct format.
If it is not, then you can manipulate the variable as required to convert it to required format and then include its value as demonstrated above using String Interpolation (#{......}).

Why do i have to put name for each object in FireBase data structure?

Lets take a look at google example for simple array
"chats": {
"one": {
"title": "Historical Tech Pioneers",
"lastMessage": "ghopper: Relay malfunction found. Cause: moth.",
"timestamp": 1459361875666
},
"two": { ... },
"three": { ... }
},
My question is why do we have to put name for each chat ? if i want to add another object i need to know which are the existing keys and create new one for which reason ? i just want a list of chats in this example and the names one two three means nothing to me...
why cant i put a list of objects with no name under chats ?
"chats": {
"one": {
"title": "Historical Tech Pioneers",
"lastMessage": "ghopper: Relay malfunction found. Cause: moth.",
"timestamp": 1459361875666
},
"two": { ... },
"three": { ... }
},
Instead of one, two and three, you can use random ids using the push() method in android, so you will have something like this:-
"chats": {
"id_1": {
"title": "Historical Tech Pioneers",
"lastMessage": "ghopper: Relay malfunction found. Cause: moth.",
"timestamp": 1459361875666
},
"id_2": { ... },
"id_3": { ... }
},
You can retrieve the key like this:-
String mGroupId = mGroupRef.push().getKey();
You can think of the ids as primary key

How to get the group name associated with username in service now by REST API

https://MYINSTANCE.now.com/api/now/table/sys_user_grmember?sysparm_display_value=all
{
"result": [
{
"sys_id": {
"display_value": "0055d61edb7fbe00115032dd7c961914",
"value": "0055d61edb7fbe00115032dd7c961914"
},
"sys_updated_by": {
"display_value": "SD1234",
"value": "SD1234"
},
"sys_created_on": {
"display_value": "09.07.2017 12:36:50",
"value": "2017-07-09 02:36:50"
},
"sys_mod_count": {
"display_value": "0",
"value": "0"
},
"sys_updated_on": {
"display_value": "09.07.2017 12:36:50",
"value": "2017-07-09 02:36:50"
},
"sys_tags": {
"display_value": "",
"value": ""
},
"user": {
"display_value": "Rahul Davis",
"link": "://MYINSTANCE.com/api/now/table/sys_user/cb154dd94f735e000d7f0ed11310c7a7",
"value": "cb154dd94f735e000d7f0ed11310c7a7"
},
"sys_created_by": {
"display_value": "SD1234",
"value": "SD1234"
},
"group": {
"display_value": "MAJOR_INCIDENT_MANAGEMENT_AU",
"link": "://MYINSTANCE.com/api/now/table/sys_user_group/2cc9e481db6b7200115032dd7c9619e3",
"value": "2cc9e481db6b7200115032dd7c9619e3"
}
}
]
}
and so on......
how can i get group name by giving username as rahul davis with sysparm with this API can anyone suggest me which one i have to use for this json format ??
First of all, you don't want to pull group membership based on a user's name, because name is not a unique value. Instead, if you can't get the user's sys_id, you might want to use their user ID. To do that, simply use a REST GET call on the following API:
https://[[INSTANCE]].service-now.com/api/now/table/sys_user_grmember?sysparm_query=user.user_name%3D[[USERNAME]]&sysparm_display_value=all
Simply replace [[INSTANCE]] with your instance name, and [[USERNAME]] with the username you're looking for. In this line above, you can see the segment in italic (sysparm_query=user.user_name%3D[[USERNAME]]) is the query. I got it, by navigating to sys_user_grmember.list from the application navigator, and running a query by dot-walking from the user field, to the user's used ID field in the query, and checking for a specific user ID.
Also, if you're looking for the group name, just append &sysparm_fields=group.name to your query URI.
You can use the "REST API Explorer" in ServiceNow to construct REST queries using the table, or other APIs, really easily in the future, if you ever need some quick help! :-)

How can I delete an id-less entity in Orion?

Question title pretty much self explanatory. It is possible to create an id-less entity in Orion. An id = .* query returns normally as an id-less, although existing entity. But how can someone delete that entity? This request didn't work obviously:
{
"contextElements": [
{
"type": "",
"isPattern": "false",
"id": ""
}
],
"updateAction": "DELETE"
}
This is the returned query:
{
"contextElement": {
"type": "",
"isPattern": "false",
"id": "",
"attributes": [
{
"name": "temp",
"type": "integer",
"value": "15"
},
{
"name": "pressure",
"type": "integer",
"value": "720"
}
]
},
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
There is a known bug (now fixed) in Orion that seems to be causing your issue. Basically Orion interprets the final "/" at the end of an URL as an empty element.
For example (as documented in the issue):
v1/contextEntityTypes queries for all types, while
v1/contextEntityTypes/ queries only for the empty type
In your particular case, something similar happens with some REST operations. If you do a GET /v1/contextEntities you will see all entities, including the empty-id one. You can query that particular entity with GET /v1/contextEntity/ (note the final "/").
And then, the DELETE method doesn't seem to use the same pattern. So if you do DELETE /v1/contextEntity/ You get a No context element found.
So, basically, this is another manifestation of a known bug.

JSON Slurper Offsets

I have a large JSON file that I'm trying to parse with JSON Slurper. The JSON file consists of information about bugs so it has things like issue keys, descriptions, and comments. Not every issue has a comment though. For example, here is a sample of what the JSON input looks like:
{
"projects": [
{
"name": "Test Project",
"key": "TEST",
"issues": [
{
"key": "BUG-1",
"priority": "Major",
"comments": [
{
"author": "a1",
"created": "d1",
"body": "comment 1"
},
{
"author": "a2",
"created": "d2",
"body": "comment 2"
}
]
},
{
"key": "BUG-2",
"priority": "Major"
},
{
"key": "BUG-3",
"priority": "Major",
"comments": [
{
"author": "a3",
"created": "d3",
"body": "comment 3"
}
]
}
]
}
]
}
I have a method that creates Issue objects based on the JSON parse. Everything works well when every issue has at least one comment, but, once an issue comes up that has no comments, the rest of the issues get the wrong comments. I am currently looping through the JSON file based on the total number of issues and then looking for comments using how far along in the number of issues I've gotten. So, for example,
parsedData.issues.comments.body[0][0][0]
returns "comment 1". However,
parsedData.issues.comments.body[0][1][0]
returns "comment 3", which is incorrect. Is there a way I can see if a particular issue has any comments? I'd rather not have to edit the JSON file to add empty comment fields, but would that even help?
You can do this:
parsedData.issues.comments.collect { it?.body ?: [] }
So it checks for a body and if none exists, returns an empty list
UPDATE
Based on the update to the question, you can do:
parsedData.projects.collectMany { it.issues.comments.collect { it?.body ?: [] } }