Skip to main content
1-Visitor
November 10, 2018
Solved

create a thing dynamically using a service and then configure it to the created project

  • November 10, 2018
  • 1 reply
  • 4368 views

I have created a project(Project A) , Template and a thing. Now i need to create 10 things dynamically using a service and then each service has to be configure a project (Project A). I am able to create a thing using a service CreateThings but while using this service it doesn''t provide the param named as project so that i can provide the name of the project  that i want it to be binded.

Best answer by shussain1

Hi Slangley,

 

Adding the answer for the above ques:

 

Step1: Need to create a thing and enable it. use the below service for the same:

var params = {
name: 'Thingabc'/* STRING */,
description: undefined /* STRING */,
thingTemplateName: 'ProjectTemplate' /* THINGTEMPLATENAME */,
tags: undefined /* TAGS */
};

// no return
Resources["EntityServices"].CreateThing(params);

Things["vc"].EnableThing();
Things["vc"].RestartThing();

 

Step2: Then use a service to bind this thing to a project as shown below:

 

var params = {
searchExpression: 'Thingabc' /* STRING */,
types: 'Thing' /* JSON */,
tags: undefined /* TAGS */
};

// no return
Projects["ProjectName"].AddEntities(params);

 

Regards,

Saddam

1 reply

shussain11-VisitorAuthor
1-Visitor
November 12, 2018

got the answer.

Support
November 12, 2018

Hi @shussain1.

 

Glad you found the solution you needed.  Would you mind sharing the details of that solution and then marking your response as the Accepted Solution?  That will help others who may have similar questions.

 

Regards.

 

--Sharon

shussain11-VisitorAuthorAnswer
1-Visitor
November 12, 2018

Hi Slangley,

 

Adding the answer for the above ques:

 

Step1: Need to create a thing and enable it. use the below service for the same:

var params = {
name: 'Thingabc'/* STRING */,
description: undefined /* STRING */,
thingTemplateName: 'ProjectTemplate' /* THINGTEMPLATENAME */,
tags: undefined /* TAGS */
};

// no return
Resources["EntityServices"].CreateThing(params);

Things["vc"].EnableThing();
Things["vc"].RestartThing();

 

Step2: Then use a service to bind this thing to a project as shown below:

 

var params = {
searchExpression: 'Thingabc' /* STRING */,
types: 'Thing' /* JSON */,
tags: undefined /* TAGS */
};

// no return
Projects["ProjectName"].AddEntities(params);

 

Regards,

Saddam