cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

EntityServices CreateThing Service does not apply Default Values

rnfonseca
9-Granite

EntityServices CreateThing Service does not apply Default Values

Hello everyone,

 

I've been trying to create 'Thing' in a batch mode, and I've decided to use the Resources["EntityServices"] CreateThing(). 

 

The service seems to work as intended. However, I can verify that the 'Thing' properties of my newly created Thing do not have the 'Default Values' I have configured. Has anyone had an issue with this in the past? 

 

Note: I'm using v8.4.1

ACCEPTED SOLUTION

Accepted Solutions

For your reference , this is the service code I am using

 

   var text    = '';
   var characters       = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    for ( var i = 0; i < 6; i++ ) {
      text += characters.charAt(Math.floor(Math.random() * i));
   }
try {
var params = {
 name: text /* STRING */,
 description: undefined /* STRING */,
 thingTemplateName: 'MyThingTemplate' /* THINGTEMPLATENAME */,
 tags: undefined /* TAGS */
};

// no return
Resources["EntityServices"].CreateThing(params);
}
catch (err)
{
    logger.warn (err.message);
}
try {
     Things[text].EnableThing();
     Things[text].RestartThing();
}
catch (err)
{
    logger.warn (err.message);
}

 

Please define ThingTemplate with name "MyThingTemplate" with default property values before using above service code.

View solution in original post

8 REPLIES 8

Hi,

 

Are you creating Thing  from specific ThingTemplate which have some properties with default values ? If you are creating thing from Generic Thing template, then how you are setting default property values on thing . Please share that code.

Hello @vinakumar ,

 

I'm creating a thing from a specific ThingTemplate which has some properties with default values.

I am not seeing any issue at my end in seeing the default property values for Things created dynamically.

@vinakumar  which version are you using?

Hi

 

As of now I tested on version 8.4.5 and found it working for me . Will test on 8.4.1 version too.

 

@vinakumar let me know if u manage to test it in version 8.4.1

Yes it is working for me on 8.4.1 too .

Please open tech support case to investigate your entity and service code you are using .

For your reference , this is the service code I am using

 

   var text    = '';
   var characters       = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    for ( var i = 0; i < 6; i++ ) {
      text += characters.charAt(Math.floor(Math.random() * i));
   }
try {
var params = {
 name: text /* STRING */,
 description: undefined /* STRING */,
 thingTemplateName: 'MyThingTemplate' /* THINGTEMPLATENAME */,
 tags: undefined /* TAGS */
};

// no return
Resources["EntityServices"].CreateThing(params);
}
catch (err)
{
    logger.warn (err.message);
}
try {
     Things[text].EnableThing();
     Things[text].RestartThing();
}
catch (err)
{
    logger.warn (err.message);
}

 

Please define ThingTemplate with name "MyThingTemplate" with default property values before using above service code.

Announcements


Top Tags