Select to view content in your preferred language

Sharing not working on script

511
3
Jump to solution
10-24-2023 12:57 PM
AngelaSchirck
Occasional Contributor III

I have built a tool that uploads/overwrites hosted feature layers on enterprise portal on a weekly basis.  The tool works fine, but the share with organization is not being recognized.  The UploadServiceDefinition help states you must be signed into portal, so I included portal sign in in my script.

I set the in_organization parameter to "SHARE_ORGANIZATION" however, when my model runs it is not sharing with the organization.

This image shows my script successfully ran and I was signed into portal, and my sharing parameter was correctly set to SHARE_ORGANIZATION:

AngelaSchirck_0-1698177093772.png

the actual script collects the parameter as input in a variable called share_organization (which can be set to SHARE_ORGANIZATION or NO_SHARE_ORGANIZATION per the ESRI documentation).

The upload command is here (uses the else clause in this particular case):

AngelaSchirck_1-1698177246835.png

Parameters collected here:

AngelaSchirck_2-1698177327206.png

I've been wracking my brain over this one...I have a similar script that publishes referenced registered data with similar settings and the share with organization part of the script (identical to this only on a federated server) works fine there.

Anybody have any idea why this is not working!?

 

 

 

 

0 Kudos
1 Solution

Accepted Solutions
AngelaSchirck
Occasional Contributor III

Okay, So for those who want to know, I found a work-around here that allows me to share with the organization (without the portal sign-on). 

In the script, after it created the sddraft, I simply opened it and changed the parameter to true using the following code (if share organization is equal to SHARE_ORGANIZATION execute the function):

```

import xml.dom.minidom as DOM

 

def changeShare(sddraftPath):
# Read the sddraft xml.
     doc = DOM.parse(sddraftPath)
     properties = doc.getElementsByTagName('PropertySetProperty')
     for property in properties:
          key = property.firstChild.firstChild.data
          try:
               if key == 'PackageUnderMyOrg':
               property.firstChild.nextSibling.firstChild.data = 'true'
               break
          except:
               continue

# Write to sddraft
     f = open(sddraftPath, 'w')
     doc.writexml(f)
     f.close()

```

View solution in original post

3 Replies
CarstenB_orsted
New Contributor III

Hi Angela,

A quick suggestion: Maybe the parameter is a string with the value 'true' or 'false' and the method expects a boolean?

You could try GetParameter instead of GetParameterAsText or convert the input to a boolean?

Something like this has thrown me off before!

Regards

Carsten

 

0 Kudos
AngelaSchirck
Occasional Contributor III

Thanks Carsten, I thought of that, but I actually found a work around!

0 Kudos
AngelaSchirck
Occasional Contributor III

Okay, So for those who want to know, I found a work-around here that allows me to share with the organization (without the portal sign-on). 

In the script, after it created the sddraft, I simply opened it and changed the parameter to true using the following code (if share organization is equal to SHARE_ORGANIZATION execute the function):

```

import xml.dom.minidom as DOM

 

def changeShare(sddraftPath):
# Read the sddraft xml.
     doc = DOM.parse(sddraftPath)
     properties = doc.getElementsByTagName('PropertySetProperty')
     for property in properties:
          key = property.firstChild.firstChild.data
          try:
               if key == 'PackageUnderMyOrg':
               property.firstChild.nextSibling.firstChild.data = 'true'
               break
          except:
               continue

# Write to sddraft
     f = open(sddraftPath, 'w')
     doc.writexml(f)
     f.close()

```