Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
MarcM
Contributor II
Contributor II

Get space name in a variable througth script - Qlik Sense Saas

Hello,

Is possible get space name in a variable throught script in the app?

I need detect this for to do one action or another depending on the space.

Thank you and regards!

Labels (2)
1 Solution

Accepted Solutions
MarcM
Contributor II
Contributor II
Author

 

 

Sub GetSpaceName(tenantFQDN,restConnection)

LET appName = DocumentName();
SET spaceName;

LIB CONNECT TO '$(restConnection)';

RestConnectorMasterTable:
SQL SELECT
	"__KEY_root",
	(SELECT
		"spaceId",
		"__FK_attributes"
FROM "attributes" PK "__KEY_attributes" FK "__FK_attributes")
FROM JSON (wrap on) "root" PK "__KEY_root"
WITH CONNECTION (
URL "https://$(tenantFQDN)/api/v1/apps/$(appName)"
);

[attributes]:
LOAD
	[spaceId]
RESIDENT RestConnectorMasterTable
WHERE NOT IsNull([__FK_attributes]);

DROP TABLE RestConnectorMasterTable;

Let spaceId = Peek('spaceId');

drop Table attributes;

// If app is in a space
if '$(spaceId)' <> '' then

  RestConnectorMasterTable:
  SQL SELECT
  	"name",
  	"__KEY_root"
  FROM JSON (wrap on) "root" PK "__KEY_root"
  WITH CONNECTION (
  URL "https://$(tenantFQDN)/api/v1/spaces/$(spaceId)"
  );

  [root]:
  LOAD 
      [name]
  RESIDENT RestConnectorMasterTable
  WHERE NOT IsNull([__KEY_root]);

  DROP TABLE RestConnectorMasterTable;
  let spaceName = Peek('name');

	DROP TABLE root;
end if;

End Sub;

 

 

And later to use variable: $(spaceName) for compare with your name space.

View solution in original post

1 Reply
MarcM
Contributor II
Contributor II
Author

 

 

Sub GetSpaceName(tenantFQDN,restConnection)

LET appName = DocumentName();
SET spaceName;

LIB CONNECT TO '$(restConnection)';

RestConnectorMasterTable:
SQL SELECT
	"__KEY_root",
	(SELECT
		"spaceId",
		"__FK_attributes"
FROM "attributes" PK "__KEY_attributes" FK "__FK_attributes")
FROM JSON (wrap on) "root" PK "__KEY_root"
WITH CONNECTION (
URL "https://$(tenantFQDN)/api/v1/apps/$(appName)"
);

[attributes]:
LOAD
	[spaceId]
RESIDENT RestConnectorMasterTable
WHERE NOT IsNull([__FK_attributes]);

DROP TABLE RestConnectorMasterTable;

Let spaceId = Peek('spaceId');

drop Table attributes;

// If app is in a space
if '$(spaceId)' <> '' then

  RestConnectorMasterTable:
  SQL SELECT
  	"name",
  	"__KEY_root"
  FROM JSON (wrap on) "root" PK "__KEY_root"
  WITH CONNECTION (
  URL "https://$(tenantFQDN)/api/v1/spaces/$(spaceId)"
  );

  [root]:
  LOAD 
      [name]
  RESIDENT RestConnectorMasterTable
  WHERE NOT IsNull([__KEY_root]);

  DROP TABLE RestConnectorMasterTable;
  let spaceName = Peek('name');

	DROP TABLE root;
end if;

End Sub;

 

 

And later to use variable: $(spaceName) for compare with your name space.