Select to view content in your preferred language

Arcade vs Portal and GetUser

1487
13
08-22-2023 10:41 AM
Markbe_utco
Occasional Contributor

I'm trying to obtain the user from one of the two portals we use.  Sometimes people are logged into both, sometimes only logged into one and sometimes not logged into either of them

Unfortunately if a person is not logged into both portals I get an error message: Failed to query url https://www.WhichEverPortalIsNotLoggedIn .com/ 

Then the script bails out

I cannot figure out how to check to see if getUser can actually obtain something in order to continue the script

var local_portal = Portal('https://gisportal.localcompany.com/portal');
var agol_portal = Portal('https://www.arcgis.com');

var local_user = getUser(local_portal);
var agol_user = getUser(agol_portal);

 

Any suggestions on how to get past this error

Tags (2)
13 Replies
CarmelConnolly
Esri Regular Contributor

What does the next part of your script do with local_user?

Does the script bail out when 'local_user' specifically or afterwards? 

0 Kudos
Markbe_utco
Occasional Contributor

The next part is to simply return the a username into an attribute field, but the script bails when it hits the getUser line.  I'm not sure how to check if the getUser can actually access the portal before it attempt to do so.

0 Kudos
CarmelConnolly
Esri Regular Contributor

Potentially something like this might work: 

if (IsEmpty(local_user) == false && IsEmpty(agol_user) == false) {
	// Result returned for local_user and agol_user items
	// Continue with script to return usernames
	
} else {
	// Result returned for agol_user only
	// Continue script to return agol_user username only

}
0 Kudos
Markbe_utco
Occasional Contributor

Thanks for the suggestion, I did try it but as I thought it still bails out before the when getUser is first used in the variable definition

var local_portal = Portal('https://gisportal.localcompany.com/portal');
var agol_portal = Portal('https://www.arcgis.com');

var local_user = getUser(local_portal);
var agol_user = getUser(agol_portal);  

The script bail out immediately when it hit either line 4 or line 5, when the user is not logged into either portal respectively.

I get this error message before it even gets to the if-then statements

Invalid expression
Error on line 4.
Failed to query url https://gisportal.localcompany.com/portal

 

0 Kudos
CarmelConnolly
Esri Regular Contributor

Can you provide the entire script you have where it's erroring on line 4?

I ask because it works for me whether I use a real or a fake 'local_portal' URL and if I'm logged in or logged out of it: 

CarmelConnolly_0-1693212094441.png

Perhaps there's something else at play here, is your 'local_portal' URL  https://gisportal.localcompany.com/portal accessible publically?

What happens if you use https://gisportal.localcompany.com/portal as the 'local_portal' URL in your script instead of (I assume) the real one?

0 Kudos
Markbe_utco
Occasional Contributor

No the 'local_portal' is not accessible publically.

During my debugging/troubleshooting I've tried to narrow it down to the barest essential lines

Also, I'm sorry that I did not mention this before; I am not using the script in a web browser interfaced session. 

The script is running within the Calculate Field tool within ArcGIS Pro using a concurrent license. Ultimately this script will, if a solutions is found, be used in an attribute rule.

 

var temp_portal = Portal ('https://www.thisfakeurlisfortestingpurposes.com')
var local_portal = Portal('https://gisportal.localcompany.com/portal');
var agol_portal = Portal('https://www.arcgis.com');

var temp_user = getUser(temp_portal);
var local_user = getUser(local_portal);
var agol_user = getUser(agol_portal);

var dummyVar = "DummyVar"
return dummyVar

 

The above script gives the error on line 5, and rightfully so because it is a fake url.

When line 5 is commented out I get the same error message now stating that the error is on line 6 when I am not logged into the 'localcompany' portal. 

If I am logged into the 'localcompany' portal I get the same error message now stating that the error is on line 7 when I am not logged into the agol. 

If I am logged into both the 'localcompany' and agol portals I don't not get any errors and the DummyVar is returned to the attribute table.

So the script is bailing out before any comparisons of variables being empty even takes place.

 

0 Kudos
CarmelConnolly
Esri Regular Contributor

Okay, that explains why my suggestion was working for me in ArcGIS Online and not for you in Pro, it doesn't work for me in Pro either!

What version of Pro and https://gisportal.localcompany.com/portal are you running?

If it's 10.9.1, there appears to be bug associated with GetUser and Attribute rules: https://community.esri.com/t5/attribute-rules-questions/getuser-10-9-1/m-p/1172250

It's fixed in a patch https://support.esri.com/en-us/patches-updates/2022/arcgis-server-10-9-1-utility-network-and-data-ma...

 

0 Kudos
Markbe_utco
Occasional Contributor

I'm running Pro 3.1.3

I'm not sure how it's a enterprise/portal issue as I am also getting the same error on my home version of Pro 3.1.3 which does not connect to any enterprise system.

I only get the error message when I'm not logged into a portal or if using a non-valid url.  When I am logged in I am able to retrieve the full name from the getUser dictionary as expected.

0 Kudos
CarmelConnolly
Esri Regular Contributor

Yes but the Portal you're trying to connect to might be 10.9.1! I've reached my limit of being able to troubleshoot, I recommend next step is to raise directly with your local Distributor Tech Support team. Referencing this post will help them as well.

Carmel