Skip to main content
17-Peridot
May 30, 2023
Solved

Set "General Information" on entity programmatically

  • May 30, 2023
  • 2 replies
  • 1739 views

Hello Community,

 

I am looking for a way to set entities "General Information". In particular I am looking to set the "Login Style", "Login Prompt" and possibly some other things of an organization from a service.

 

I could find a "SetHomeMashup", but I can't seem to find any other service that fulfills this requirement.

Does anyone have any ideas?

 

Thanks,

Jens

Best answer by nmutter

I also do not know of any service to do so.

 

What would most likely work is hacky and not nice to use (did not try it myself).. But if you really need it:

1. Use entityAsJson = Resources["EntityServices"].ReadEntityAsJSON with type "Organizations" and name "yourorgname"

2. In the result adapt login prompt e.g. entityAsJson.loginPrompt="Hello world"

3. Save the entity by creating a PUT request with ContentLoader functions to http://localhost/Thingworx/Organizations/yourorgname with the entityAsJson  in the body (the same what composer does when you save the entity)

To make the request you will need an appkey with the needed permissions and pass it as a header...

 

2 replies

17-Peridot
May 31, 2023

I belive, we can't updat the "General Information" in single go. We have update each parameter separately.

Example:

Things["SecurityMonitor"].SetAvatar({
	content: undefined /* IMAGE */
});
Things["SecurityMonitor"].SetDescription({
	description: undefined /* STRING */
});
Things["SecurityMonitor"].SetProjectName({
	projectName: undefined /* PROJECTNAME */
});
Things["SecurityMonitor"].SetTags({
	tags: undefined /* TAGS */
});

 

jensc17-PeridotAuthor
17-Peridot
May 31, 2023

Hello @Sathishkumar_C,

 

Thank you for your reply.

Yes I do think this is the way to do it. Unfortunately there is no service for setting the information I want to set:

jensc_0-1685513581089.png

Like setting the login prompt etc... 

It does seem unlikely that there is a way to do this though...

 

Thanks,

Jens

17-Peridot
May 31, 2023

not sure on login prompt.

you can use following service to updat the style definition.

let params = {
	name: undefined /* STYLEDEFINITIONNAME */,
	content: undefined /* JSON */
};
// no return
Resources["EntityServices"].UpdateStyleDefinition(params);

please refer Style definition using scripts

 

nmutter16-PearlAnswer
16-Pearl
May 31, 2023

I also do not know of any service to do so.

 

What would most likely work is hacky and not nice to use (did not try it myself).. But if you really need it:

1. Use entityAsJson = Resources["EntityServices"].ReadEntityAsJSON with type "Organizations" and name "yourorgname"

2. In the result adapt login prompt e.g. entityAsJson.loginPrompt="Hello world"

3. Save the entity by creating a PUT request with ContentLoader functions to http://localhost/Thingworx/Organizations/yourorgname with the entityAsJson  in the body (the same what composer does when you save the entity)

To make the request you will need an appkey with the needed permissions and pass it as a header...

 

jensc17-PeridotAuthor
17-Peridot
June 1, 2023

Hello @nmutter,

 

I did a test and this absolutely worked!

Perhaps as you say it is a little bit hacky, but as I do not see any other way of doing it, this will have to work.

 

Thanks,

Jens