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

DEVELOPERS FORUM - Returning custom XML from a method

Santhosh - Wednesday, March 2, 2011 7:32 AM:

Hi Community,

I'm trying to read two different item types and form a custom XML and return the same, which is not working.

Below is the code which I'm using to return.


' MethodTemplateName=VBScriptMainUpgrade;

Sub MethodMainSubRoutine()
 Dim myInn As Innovator = New Innovator(Me.InnovatorObject)
 Dim curItem As item = myInn.newItem("Project")
 Dim proj_Num As Integer = 0
 Dim baseline_proj_Num As String = String.Empty
 Dim strOutput As New StringBuilder()
 Dim strAML As String = ""
 Dim level As Integer = 0
   
 curItem.loadAML(inDom.selectSingleNode("//Item").outerXml)
 proj_num = curItem.getProperty("project_number")
 strAML = "" & _
 "<Item type='Project Baseline' action='get' select='*' where=" & """" & "[Project_Baseline].project_number like '" & proj_num.ToString & "B%'" & """" &"/>"
 Dim tempItem As Item = myInn.newItem("Project Baseline")
 tempItem.loadAML(strAML)
 Dim tmpItem As Item = tempItem.apply()
 Dim ItemCount As Item = tmpItem.getItemsByXPath("//Item[@type='Project Baseline']")
 Dim PrevCount As Integer = 0
 Dim i As Integer = 0
 Dim ProjectName As String
 For i = 0 To (ItemCount.getItemCount() - 1)
  If ItemCount.getItemByIndex(i).GetType() = "Project Baseline" Then
   ProjectName = ItemCount.getItemByIndex(i).getProperty("project_number").ToString
   If ProjectName.Contains(proj_num.ToString) Then
    PrevCount = PrevCount + 1
   End If
  End If
 Next
 If PrevCount = 0 Then
  outDom.LoadXml(myInn.newError("No Baseline found for current project. Please create baseline of the project using Actions -> Baseline Project menu").dom.outerXML)
 End If
 baseline_proj_num = proj_num.ToString & "B_" & PrevCount.ToString
 
 Dim Doc As System.XML.XMLDocument = New System.XML.XmlDocument()

    'Beginning of appending project information
    strAML = "" & _
    "<Item type='Project Baseline' action='get' select='*'>" & _
    " <project_number condition=" & """" & "eq" & """" & ">" & baseline_proj_num & "</project_number>" & _
    "</Item>"
    Dim tmpPrjBase As Item = myInn.newItem("Project Baseline")
    tmpPrjBase.loadAML(strAML)
    Dim Prj_Baseline As Item = tmpPrjBase.apply()   
    Dim strXML As String = ""
   
    strXML = "<Projects>"
    strXML = strXML & "<Project Name='" & curItem.getProperty("name").ToString & "'" & _
    " Project_Number='" & curItem.getProperty("project_number").ToString & "'" & _
    " Version='" & PrevCount.ToString & "'" & _
    " Scheduled_Start_Date='" & curItem.getProperty("date_start_sched").ToString & "'" & _
    " Scheduled_End_Date='" & curItem.getProperty("date_due_sched").ToString & "'" & _
    " Target_Start_Date='" & curItem.getProperty("date_start_target").ToString & "'" & _
    " Target_End_Date='" & curItem.getProperty("date_due_target").ToString & "'" & _
    " Initial_Start_Date='" & Prj_Baseline.getProperty("baseline_ini_startdate").ToString & "'" & _
    " Initial_End_Date='" & Prj_Baseline.getProperty("baseline_ini_enddate").ToString & "'" & _
    " Current_Start_Date='" & Prj_Baseline.getProperty("baseline_cur_startdate").ToString & "'" & _
    " Current_End_Date='" & Prj_Baseline.getProperty("baseline_cur_enddate").ToString & "'/>"
    strXML = strXML & "</Projects>"

    Doc.LoadXML(strXML)
    'End of appending project information
       
    outDom.LoadXml(Doc.outerXml)
End Sub

When I execute this method a blank string is returned.

I even tried using myInn.newResult(Doc.OuterXML.ToString) which also returns blank.

This is very important for me, could somebody help me with this please. How to return custom XML.

Please suggest if there are any other approaches.

Santhosh



Santhosh - Wednesday, March 2, 2011 11:45 PM:

Basically I'm tying  to achieve is compare two different Item types and their respective relations and form the result in an XML Document and return the same.

Could anyone please suggest a way to do this.

Santhosh



aknourenko - Monday, March 7, 2011 10:03 AM:

Santhosh,

It's not clear from your post what do you mean by "execute this method". Without this information it's difficult to figure out why it does not work for you.

In general you definitely should be able to return any valid XML from your method. I've done a very simple experiment intentionally using exactly the same template "VBScriptMainUpgrade" that you use (although it's not clear to me why you've chosen this particular template; to be able to get back outDom XML rather than Item the typical choice is "VBScriptInOut" template) and got back my custom XML:

 

My method code:

'created: 7-MAR-2011 Andrey Knourenko
'MethodTemplateName=VBScriptMainUpgrade;

Sub MethodMainSubroutine()
    Dim xml As String = "<foo>test</foo>"

    outDom.LoadXML(xml)
End Sub

 

Then I'm sending the following AML through nash.aspx using SOAP action "ApplyItem":

<Item type='Part' action='fooTest' />

and get back <foo>test</foo>. Note that a) it does not matter what item type you specified in this case; you just have to specify something to make "ApplyItem" SOAP action to pass validation; b) you can use a different SOAP action (e.g. "ApplyMethod") using a corresponding for the SOAP action AML (i.e. most probably will be slightly different from the AML above) which should produce the same result. NOTE: the reason I used "ApplyItem" SOAP action was because this is what IOM.Item.apply(...) uses.



Brian - Saturday, March 5, 2011 11:51 PM:

Hi Santosh,

I always find it a good thing to check the results of the LoadXML call.

Put this:

if ( Doc.parseError.errorCode != 0)
{
    Dim myErr as string
    myErr = Doc.parseError
}

And test to see what it is in Debug or return the error to the client.

Hope this helps.

Cheers,

Brian.



Santhosh - Tuesday, March 8, 2011 2:26 AM:

Hi Andrey,

I'm quite new to this ARAS application so trying to understand. In the process, I'm trying to read two different item types and prepare my own XML and return the same.

I have gone through some of the existing methods and found this "VBScriptMainUpgrade" and started working with it. I have no idea of how to use "VBScriptInOut" template.

Based on your input I tried one more simple example and connected it to a report.

' MethodTemplateName=VBScriptMainUpgrade;
Sub MethodMainSubRoutine()
 Dim myInn As Innovator = New Innovator(Me.InnovatorObject)
 Dim curItem As item = myInn.newItem("Project")
 Dim strXML As String = ""
 
 curItem.loadAML(inDom.selectSingleNode("//Item").outerXml)
           
 strXML = "<Project Name='" & curItem.getProperty("name") & "' Project_ID='" & curItem.getId() & "'></Project>"

 outDom.loadXML("<Result>"+strXML+"</Result>")                  'This I found in another existing method named "is_identity_in_role"
End Sub

But when I call for the report it is throwing an error saying "Root Element is missing".

But the same method when I run from "Actions -> Run Server Method" I'm able to see the output.

I'm not able to understand what is going wrong when I try to run the same method using a report. This is making me little frustated because I have been trying to do this from one week now but not able to succeed.

Santhosh

 



Santhosh - Monday, March 7, 2011 6:44 AM:

Hi Brain,

I'm wondering if "parseError" cn be used with XMLDocument.

I think this method is in VB6 right....with DOMDocument......

if the same method can be used in VB.net with XMLDocument, please let me know how to do that....

cheers,

Santhosh.



aknourenko - Tuesday, March 8, 2011 11:50 AM:

Well, I don't think you ever mentioned in this blog that you want to build a report ... First of all, there are two types of reports in Innovator - XSLT report (which I believe you are trying to implement) and MS Report Services reports. In order to understand how to build XSLT report read "Aras Innovator9.2 - XSLT Report Tool Users Guide.pdf" on Aras web site. Again, in general, it's all possible but in case of report it might depend on your stylesheet and few other things.



Brian - Monday, March 7, 2011 7:02 AM:

Hi Santhosh,

This is the example Microsoft use with VB and loadXML.

Dim xmlDoc As New Msxml2.DOMDocument30
xmlDoc.async = False
xmlDoc.loadXML ("<customer>" & _
                "<first_name>Joe</first_name>" & _
                "<last_name>Smith</last_name></customer>")
If (xmlDoc.parseError.errorCode <> 0) Then
   Dim myErr
   Set myErr = xmlDoc.parseError
   MsgBox("You have error " & myErr.reason)
Else
   MsgBox xmlDoc.xml
End If

This is the page:  http://msdn.microsoft.com/en-us/library/ms754585(v=vs.85).aspx#Y828

People don't mind answering questions but it is always good to see that someone is willing to look for themselves.

This took me less than 30seconds to find with a Google search.

Hope this helps.

Brian.



Santhosh - Tuesday, March 8, 2011 1:01 PM:

Hi Andrey,

I have gone thorugh the pdf. I have done some reports using XSLT.

Could you please help me giving any example on how to use "VBScriptInOut" and return a customized XML.

Thanks

Santhosh



Santhosh - Monday, March 7, 2011 8:17 AM:

Hi Brain,

MSXML2.DOMDocument30 is not by default in VB.net. We have add a dll named "msxml3.dll" as a reference to our project, then only we can use the above example.

I have been trying to return the XML using default VB.net System.Xml.XmlDocument.

I have debugged by method and found that XML is getting loaded into the Doc object without any issues. But when I'm trying to return the document it is not getting returned.

I'm wondering in ARAS can we return our own XML or anything other than Item.

Please advice.

 Santhosh



aknourenko - Tuesday, March 8, 2011 2:38 PM:

You can find all templates in ${Innovator Home Dir}Servermethod-config.xml file. I don't think though that changing template will resolve your problem; all I meant mentioning "VBScriptInOut" template was that this template is typically used when users want to operate with inDomoutDom rather than with Items. As for its usage, here is how my example will look like using "VBScriptInOut" template:

'created: 7-MAR-2011 Andrey Knourenko
'MethodTemplateName=VBScriptInOut;

Dim xml As String = "<foo>test</foo>"

outDom.LoadXML(xml)

Based on your previous post it seems that in general (e.g. using action) you are able to return a custom XML from your server method and your problem is in using this in report. My guess would be that your stylesheet is wrong. Another suggestion would be to play with your method output - for instance return <Item type='foo'><foo>test</foo></Item> instead of just <foo>test</foo> and to see what happens with the report.

Hope it'll help.



Santhosh - Wednesday, March 9, 2011 2:19 AM:

Hi Andrey,

This worked for me and I was able to get my desired result. As per your suggestion, I have checked through my XSL and found the problem. It is working for me now.

Thank you very much for your time and help.

Brain ~ Thank you very much for your time and help.

Cheers

Santhosh