This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Identity Manager - C# Mapping Script Documentation

I need to port the following VB script to C# because I can't change connector scripting language anymore.

I can't find any documentation about that. Any help? Thanks

Imports VI.Projector.Connection
Dim dn AS String
dn = SystemObject.Connection.QueryObject(SystemQuery _
 .From("ADSAccount") _
 .Select("DistinguishedName") _
 .Filter(String.Format("SAMAccountName='{0}'", $VRT_Manager$))) _
 .Result.First.GetValue("DistinguishedName").AsString
return dn

  • Something similar to this should work:

    {
        using VI.Projector.Connection;
        string dn = "";
        dn = SystemObject.Connection.QueryObject(SystemQuery 
        .From("ADSAccount") 
        .Select("DistinguishedName") 
        .Filter(String.Format("SAMAccountName='{0}'", $VRT_Manager$)))
        .Result.First.GetValue("DistinguishedName").AsString;
        return dn;
    }

  • Hello. I tried but I got this error.

    [1777156] The following errors occured while compiling:
    
    CS0119: 'System.Linq.ParallelEnumerable.First<TSource>(System.Linq.ParallelQuery<TSource>, System.Func<TSource,bool>)' is a 'method', which is not valid in the given context
    Position: Set-Script of ScriptEditor (VRT_Manager)
    Line: 6 Column: 13
    
    	at VI.Projector.UI.Controls.ScriptControl._Compile()
    	at VI.Projector.Scripting.ScriptProcessor.Process()
    	at VI.Projector.Scripting.ScriptCompiler.Compile(Boolean throwOnError)
    
    

  • I always use the online code converter as starting point

    And if this is not working I debug the errors with the build in Visual Studio Debug support.

  • Cheers MWE! I didn't know that existed.
    You will probably need to wrap the VB.NET code in a fake function that returns a string.
  • BTW, it returns:

        string dn;
        dn = SystemObject.Connection.QueryObject(SystemQuery.From("ADSAccount").Select("DistinguishedName").Filter(string.Format("SAMAccountName='{0}'", ))).Result.First.GetValue("DistinguishedName").AsString;
        return dn;

    So I was pretty close.  Not bad from memory.

     

    You also have to remove the "using" for syntax reasons.  I think if you put it back it will be fine.

  • Also, I can tell there is at least one syntax error.  It's stripping the $<parameter>$.  So this is closer:

     string dn;
        dn = SystemObject.Connection.QueryObject(SystemQuery.From("ADSAccount").Select("DistinguishedName").Filter(string.Format("SAMAccountName='{0}'", $VRT_Manager$))).Result.First.GetValue("DistinguishedName").AsString;
        return dn;

    And Markus is right, at this point Visual Studio is your friend.

  • I tried with the code

    string dn;
    dn = SystemObject.Connection.QueryObject(SystemQuery.From("ADSAccount").Select("XObjectKey").Filter(string.Format("SAMAccountName='{0}'", value))).Result.First.GetValue("XObjectKey").AsString;
    

    But the compilation still fails.

    [1777156] The following errors occured while compiling:
    
    CS0103: The name 'SystemQuery' does not exist in the current context
    Position: Set-Script of ScriptEditor (VRT_Manager)
    Line: 2 Column: 42
    

    I can't find any working C# example in the documentation and I can't do anything in visual studio because I don't know what this is  around that script.

    I need to find XObjectKey using SAMAccountName to set ObjectKeyManager in ADSAccount.

    Resolve key is not working so I tried a script to find out a solution.

  • I find out the correct syntax and the C# script now works.

    using VI.Projector.Connection;
    string dn;
    IQueryObject qo = SystemQuery.From("ADSAccount").Filter(String.Format("SAMAccountName='{0}'", value)).Select("XObjectKey");
    QueryObjectResult r = SystemObject.Connection.QueryObject(qo);
    dn = r.Result.First().GetValue("XObjectKey").AsString;
    $ObjectKeyManager$ = dn;

    I also find out that the problem is different from what I was thinking. I cannot update the ObjectKeyManager in ADSAccount. I'll open a new thread about it.