action script check tenant

action script check tenant

PLM-Sylvain.Bailly
Collaborator Collaborator
637 Views
4 Replies
Message 1 of 5

action script check tenant

PLM-Sylvain.Bailly
Collaborator
Collaborator

Hello,

 

We have a production server and a sandbox. We have linked the PLM with the ERP and when an item is saved in PLM, we migrate the information to the ERP. The problem is when we put a backup of the production server to the sandbox, this scripts are also copied. So, if we do some tests on the items of the sandbox, the scripts populate the ERP with wrong data. Is it possible to have a check on the tenant in the action script to say: "if the tenant is the one of the production server, do the script. If not, do nothing"?

I don't know how to catch the tenant or the URL of the server. There is not a magic function 'getTenant()'?

 

Thx

Sylvain

0 Likes
638 Views
4 Replies
Replies (4)
Message 2 of 5

bastien.mazeran
Autodesk Support
Autodesk Support

Hello Sylvain,

 

Please review https://forums.autodesk.com/t5/fusion-lifecycle-forum/determine-tenant-environment-during-script-exe....

 

Thank you,



Bastien Mazeran

Technical Support Specialist

0 Likes
Message 3 of 5

john.denner
Advocate
Advocate

I have a workspace setup where I can configure my tenant to my needs for certain circumstances. For instance, I have a field that defines production/sandbox, integration urls (they differ when testing), send emails on/off. etc.

 

The code below is extremely basic examples to show what it could be used for. I didn't want to type out all the additional code and variables, proper function arguments, etc. 🙂

 

var tenantSettings = loadItem(8675309);
var linkBack = tenantSettings.URL + '/...';

if (tenanSettings.isProduction) {
  // Do stuff
}

var url =  tenantSettings.integrationEndpoint;

function integration(url) {
  xhr = new XMLHttpRequest();
  // Code
  if (tenantSettings.integrationActive) {
    xhr.send();
  } else {
    Logger.log(); 
  }
}

function mailStuff() {
  // Code
  if (tenantSettings.sendMail) {
    mail.send();
  } else {
    Logger.log(xhr.responseText); // optionally throw in mail properties
}
0 Likes
Message 4 of 5

PLM-Sylvain.Bailly
Collaborator
Collaborator

I have tested the library script which declare a variable "Production" and use it after in my action script with a "if" condition and it works. But it is a makeshift job. You are obliged to modify this library script after the migration of the Production server to the test server. If you forget and it will happen, we will pollute the ERP. It is not a solution for me and it must not be like it. We must have access to the url to check if what we declare in the library script correspond to the tenant.

0 Likes
Message 5 of 5

john.denner
Advocate
Advocate

It's indeed a workaround but it's a workaround for an issue that is related to how cloud infrastructure works so that's a tricky one.

 

I used to use a variable in my scripts but ran into the same issue of needing to go back into my code and adjust the variable. That's why I moved it to a checkbox in a workspace. It's only slightly better but easier to see, maintain, delegate, etc.

 

On my way in to work I was thinking maybe you could do an API request and then evaluate the request headers to get the requesting host domain. But that seems even more problematic than a checkbox in a workspace. 🙂

0 Likes