Skip to main content
1-Visitor
July 3, 2018
Solved

How to create style definition through services in thingworx ?

I need to get the input from the front end mashup then i like to create the style definition based on the input using services, further i like to update the particular widgets style definition with that newly created style.

 

thanks in advance...

1-Visitor
July 4, 2018

Combining both and after some tests, this is the correct format :

 

var name = "NewTestStyle3";
try{
 Resources["EntityServices"].CreateStyleDefinition({
 name: name,
 description: undefined ,
 content: { "content" : 
 { "params": "",
 "image":"",
 "backgroundColor":"#d49d13",
 "textSize":"normal",
 "lineStyle":"dotted",
 "displayString":"Series 15",
 "fontEmphasisUnderline":false,
 "fontEmphasisItalic":false,
 "lineThickness":1,
 "lineColor":"#ffac20",
 "foregroundColor":"#ffdc84",
 "fontEmphasisBold":false,
 "secondaryBackgroundColor":"#ffb22f"
 
 }
 },
 tags: undefined 
 });


}catch(err) {
 logger.error("EERROR STYLE CREATION "+err);
 Resources["EntityServices"].DeleteStyleDefinition({
 name: name
 });
}

4 replies

5-Regular Member
July 3, 2018

There is a snippet:

 

var params = {
	name: undefined /* STRING */,
	description: undefined /* STRING */,
	content: undefined /* JSON */,
	tags: undefined /* TAGS */
};

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

But I don't know how to use it properly.  I am curious about how to do this too.  

Translate
1-Visitor
July 4, 2018

thank you for your reply xavior,

i know there is a separate snippet available in the service part. but i also dont know how to use that one.

 

In that snippet where do we need to give input for color code and text format? 

Translate
1-Visitor
July 4, 2018

If you look at my answer on how to get Style Information: https://community.ptc.com/t5/ThingWorx-Developers/Get-style-information-of-style-definition/m-p/548275

 

you can see that the context format for style may look something like:

 

{ 
 "image":"",
 "backgroundColor":"#d49d13",
 "textSize":"normal",
 "lineStyle":"dotted",
 "displayString":"Series 15",
 "fontEmphasisUnderline":false,
 "fontEmphasisItalic":false,
 "lineThickness":1,
 "lineColor":"#ffac20",
 "foregroundColor":"#ffdc84",
 "fontEmphasisBold":false,
 "secondaryBackgroundColor":"#ffb22f"
}
Translate