MicroStrategy SDK - User Properties

microstrategy-sdk

https://lw.microstrategy.com/msdz/MSDL/902/docs/Reading_User_Properties.htm
https://lw.microstrategy.com/msdz/MSDL/900/docs/Using_Extended_Properties.htm
http://community.microstrategy.com/t5/MicroStrategy-Software/Retrieving-Extended-Properties/td-p/17856

How can we work with custom / extended user properties?

In the SDK documentation, there is an article titled "Reading User Properties", so search the SDK documentation for that phrase.

All user objects have a set of basic properties. However, users can be given additional extended properties. The sample code below illustrates how to read all of the extended properties for a user.

package com.microstrategy.sdk.samples.usermanagement;

import com.microstrategy.web.objects.WebFolder;
import com.microstrategy.web.objects.WebIServerSession;
import com.microstrategy.web.objects.WebObjectSource;
import com.microstrategy.web.objects.WebObjectsException;
import com.microstrategy.web.objects.WebObjectsFactory;
import com.microstrategy.web.objects.WebProperty;
import com.microstrategy.web.objects.WebPropertyGroup;
import com.microstrategy.web.objects.WebPropertySet;
import com.microstrategy.web.objects.WebSearch;
import com.microstrategy.web.objects.admin.users.WebUser;
import com.microstrategy.webapi.EnumDSSXMLApplicationType;
import com.microstrategy.webapi.EnumDSSXMLObjectSubTypes;
import com.microstrategy.webapi.EnumDSSXMLSearchDomain;

public class ReadUserPropertySets {
    public static WebIServerSession sessionInfo;
    public static final String userName = "New User";

    public static void main(String[] args) {
        sessionInfo = getServerSession(iServerName, projectName, adminLoginName, adminLoginPasswd);
        WebObjectSource  source =sessionInfo.getFactory().getObjectSource();

        if(user!=null){
            try {
                WebPropertyGroup wpg = user.getPropertySets();

                for(int i=0; i< wpg.size(); i++){
                    WebPropertySet wps = wpg.get(i);
                    System.out.println(wps.getName());
                    for(int j=0; j<wps.size(); j++) {
                        WebProperty wp = wps.get(j);
                        System.out.println("\t"+wp.getName()+": " +wp.getValue());
                    }
                }
            } catch (WebObjectsException e) {
                e.printStackTrace();
            }
        }
    }
}

In the above code, we first invoke user.getPropertySets() to get all the property sets. We then loop over this collection, and for each property set, we print out its name, and then we loop over all properties that are contained within this property set, print out the property's value. So, we can have multiple properties within a property set, and each property set can have a name, and each user can have multiple property sets as well.

Can we use extended on any object other than users?

Yes. We can use extended properties with different objects, such as Projects, Reports, and Documents. All of these objects have public methods to access properties and property sets.

How can we access extended properties?

//Fetch property set from object by passing the object type (report, project, etc) and the name of the property
WebPropertySet  propSet = myObject.getPropertySet(objectType, propertySetName);

//Fetch the property that we want to get access to by passing its name
WebProperty  property = propSet.getItemByName(propertyName);

//Fetch the value of the property and save it to a string variable
Sring  propertyValue = property.getValue();

How can we assign a new value to an existing property?

//Set a new value for the property
property.setValue(“newValue”);

//Save the property set back into the object
propSet.save();

How can we fetch the extended properties from a report object?

/***
Get a report property value. <BR>
* It can retrieve any property in any property set. Thus it may trigger a Iserver call. <BR>
* @param rb the ReportBean object
* @param reportObjectType the object type (EnumDSSXMLReportObjects) for which the property will be
* @param propertySetName the property name
* @param propertyName the property name
* @return the property value
*/
private static String getReportInstancePropertyValue(ReportBean rb, int reportObjectType, String propertySetName, String propertyName) {
    String __result = "";
    try {
        WebPropertySet ps = null;
        ps = rb.getReportInstance().getPropertySet(reportObjectType, propertySetName);
        __result = ps.getItemByName(propertyName).getValue();
        ps.getItemByName(propertyName).setValue(__result);
    } catch (WebBeanException ex) {
        // Couldn't retrieve report instance from report bean (rb)    
    } catch (WebObjectsException ex) {
        // Couldn't retrieve property sets from report instance for report bean (rb)    
    }
    return __result;
}

/**
 * Set a report property and saves it <BR>
 * It can set any property in any property set. <BR>
 * @param rb the ReportBean object
 * @param reportObjectType the object type (EnumDSSXMLReportObjects) for which the property will be
 * @param propertySetName the property name
 * @param propertyName the property name
 * @param propertyValue the value to set on the specified property
 */
private static void setReportInstancePropertyValue(ReportBean rb, int reportObjectType, String propertySetName, String propertyName, String propertyValue) {
    try {
        WebPropertySet ps = null;
        ps = rb.getReportInstance().getPropertySet(reportObjectType, propertySetName);
        ps.getItemByName(propertyName).setValue(propertyValue);
        ps.save();
    } catch (WebBeanException ex) {
        //Couldn't retrieve report instance from report bean (rb)    
    } catch (WebObjectsException ex) {
        //Couldn't retrieve property sets from report instance for report bean (rb)    
    }
}

How can we fetch extended properties from a Project Object?

try {
    propertySet = session.getFactory().getProjectSource().getProjectProperties("DefaultProjectProperties");
    if (propertySet != null) {
        WebProperty property = null;
        property = propertySet.getItemByName("ReportSaveAs8iWarning");
        if (property != null) {
            property.setValue(value);
            property.save();
        }
    }
} catch (WebObjectsException woe) {
    //Error in retrieving and saving PropertySet:DefaultProjectProperties, Property: ReportSaveAs8iWarning
}

How can we use the Extended Property Editor that is part of the SDK?

This Extended Property Editor is only available on Windows environment.

  1. Access the Extended Properties Editor from Start -> Programs -> MicroStrategy -> SDK -> Sample Utilities
  2. On the Extended Property Editor dialog, select New Connection from the File menu. The Login dialog opens.
  3. In the Login dialog:
    1. In the Select a data source pane, select the appropriate 3-tier business intelligence datasource from the list of projects.
    2. In the Select a root object pane, select Project
    3. Under Authentication mode, select Standard or NT Identity. If you choose Standard, enter the appropriate username and password.
    4. Click the Login button to continue. If login is successful, the Select a project dialog opens. If you are using these steps to perform the Implementing Writeback Functionality scenario, you should choose MicroStrategy BI Developer Kit in the Select a data source pane.
  4. On the Select a project dialog, choose a project and click OK. The Extended Properties Editor dialog opens. If you are using these steps to perform the Implementing Writeback Functionality scenario, you should choose MicroStrategy Tutorial as the project.
  5. On the Extended Properties Editor dialog, select Add from the Property Set menu. The Property Set Editor dialog opens.
  6. On the Property Set Editor dialog, create a new property set. Enter "WritebackProps" in the Property Set Name text field and click the Add button. The Property Editor dialog opens.
  7. On the Property Editor dialog, create a new property. Under Associate one or more objects with this property, check the Report checkbox to associate this new extended property with the report object.
  8. Click OK to close the Property Editor dialog.
  9. Click Save in the Property Set Editor dialog
  10. Exit the Extended Properties Editor dialog.

How can we use extended properties?

All user objects have a set of basic properties. However, users can be given additional extended properties.

Look at the API documentation for WebProperty, WebPropertyGroup, WebPropertySet. Search the SDK documentation for "Reading User Properties"

WebPropertyGroup wpg = user.getPropertySets();
for (int i=0; i< wpg.size(); i++) {
    WebPropertySet wps = wpg.get(i);
    System.out.println(wps.getName());
    for (int j=0; j<wps.size(); j++) {
        WebProperty wp = wps.get(j);
        System.out.println("\t"+wp.getName()+": " +wp.getValue());
    }
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License