Skip to main content
Jul 5, 2018 5:55 AM UTC
Solved

Enable thing() and Restart thing() from Eclipse Extension

Hi All,

I want to make a thing to Enable and Restart within Eclipse Extension.

How can i do this?

 

Thing things = new Thing();

things.Enable Thing();

things.RestartThing();

 

Above code is not working.

 

Thanks & Regards,

Sathishkumar C.

supandeyAnswer
Jul 10, 2018 9:48 AM UTC

@Sathishkumar_C In that case I think the issue might be that you are attempting start / enable of thing on template level and that's not possible. You need to attempt that on the object , something like this 

 

@ThingworxServiceDefinition(name = "CreateAThing", description = "", category = "", isAllowOverride = false, aspects = {
			"isAsync:false" })
	@ThingworxServiceResult(name = "Result", description = "", baseType = "BOOLEAN", aspects = {})
	public void CreateAThing() throws Exception {
		_logger.trace("Entering Service: CreateAThing");
		_logger.trace("Exiting Service: CreateAThing");

		EntityServices newThingService = new EntityServices();

		String name = "UniqueThingName";
		String desc = "Static Thing from Custom Extension";
		TagCollection myTag = null;

		try {
			newThingService.CreateThing(name, desc, myTag, "ExtensionStandardNew");
		} catch (Exception e) {
			System.out.println("Failed to create Thing");
			e.printStackTrace();
		}

		Thing mything = (Thing) EntityUtilities.findEntity(name, ThingworxRelationshipTypes.Thing);
		_logger.trace("Failed to find thing", mything.getName());

		try {
			mything.EnableThing();
		} catch (Exception e) {
			System.out.println("Failed to enable thing" + mything.getName());
			e.printStackTrace();
		}

8 replies

Jul 9, 2018 8:48 AM UTC

Hi @Sathishkumar_C could you share exactly what sort of error / issue you are running into?

Jul 9, 2018 9:31 AM UTC

I can't able to enable and restart the thing after creation.

Jul 9, 2018 11:01 AM UTC

Do you mean once you import the extension you can't enable and restart those Entities? could you please share any screenshot or template detail you are working with?