Informix: extractvalue: Extract nth element's attribute value using XPATH - attributes

I am trying to write an Informix stored procedure that extracts some xml elements values and attribute values using extractvalue function.
How do I extract 2nd person's id using xpath in Informix? I tried the following and its returning null:
DROP PROCEDURE sp_parse_xml;
CREATE PROCEDURE sp_parse_xml()
RETURNING LVARCHAR(256);
DEFINE l_set SMALLINT;
DEFINE l_node_value LVARCHAR(256);
DEFINE xml_string LVARCHAR(8000);
LET l_set = 0;
LET xml_string = '<personnel><person id="Jason.Ma"><name><family>Ma</family><given>Jason</given></name></person><person id="12345"><name><family>Smith</family><given>John</given></name></person><person id="67890"><name><family>Cook</family><given>Peter</given></name></person></personnel>';
LET l_node_value = extractvalue(xml_string, '/personnel/person[2]/#id');
--RETURN existsnode(xml_string, '/personnel/person[2]/#id');
RETURN l_node_value;
END PROCEDURE;
Thanks for your help.

Related

Filter leading to different results when typed manually and via defined as a variable

I'm trying to create a calculated column indicating if a team has a prize or not from the table below:
To do that I need to count within the group if there's a player whose "Prize" field is not empty. Here's the 1st attempt:
Dax Formula:
=
Var Player_Same_Team = filter(Table4,Table4[Team]=earlier(Table4[Team]))
Var Has_Prize = len(Table4[Prize])>0
Return
calculate(countrows(filter(Table4,len(Table4[Prize])>0)),Player_Same_Team)>0
Looks like it's going what I intend it to do. However, when I swap the filter content to a pre-defined variable, it gave me results that don't make sense:
Dax Formula:
=
Var Player_Same_Team = filter(Table4,Table4[Team]=earlier(Table4[Team]))
Var Has_Prize = len(Table4[Prize])>0
Return
calculate(countrows(filter(Table4,Has_Prize)),Player_Same_Team)>0
The typed content len(Table4[Prize])>0 is the same as that in the variable, so what may be causing the difference? Thanks for your help.
As soon as you assign it to a variable, the value of the variable remains constant. Therefore the Len is evaluated to a value, that you are then passing as a filter.
The first example works because the CALCULATE accepts a table as a parameter, and player_same_team is evaluated to a table, by using the FILTER expression.
In order for what you are trying to do to work it would have to be something like this:
= Var Player_Same_Team = filter(Table4,Table4[Team]=earlier(Table4[Team]))
Var Has_Prize = filter(Table4,len(Table4[Prize])>0)
Return calculate(countrows(Has_Prize),Player_Same_Team)>0
You can also write the measure in a slightly different way:
= CALCULATE ( COUNT(Table4[Team]),
ALLEXCEPT(Table4[Team]),
LEN(Table4[Prize])>0) > 0

Unable to retrieve custom list value from saved search in netsuite

Creating saved search in suitescript using nlapiSearchRecord. All the column value returns except one column which is type is custom list.
How could I get value of custom list?
To get the value I'm using code lines below.
columns[0] = new nlobjSearchColumn( 'customlist' );
var searchresults = nlapiSearchRecord( 'customrecord', null, filters, columns );
To get the column value
var listValue = searchresult.getListValue( 'customlist' );
I assume you've simplified your code in trying to be clear or confidential but there will never be fields or records with those ids.
from a search you would do:
var searchResult = searchResults[0];
searchResult.getValue(fieldId, joinName, summary)
// or in your case
searchResult.getValue('customlist'); //returns id of list value or simple result of non-list/record fields
or (and I think this is the one you want)
searchResult.getText('customlist'); // returns the display value of the list/record field.

Trying to build Excel RTD server in Delphi

I'm trying to build an RTD server for Excel in Delphi and I cannot get this part of the code to work:
function TRtdServer.RefreshData(var TopicCount: Integer): PSafeArray;
//Called when Excel is requesting a refresh on topics. RefreshData will be called
//after an UpdateNotify has been issued by the server. This event should:
//- supply a value for TopicCount (number of topics to update)
//- The data returned to Excel is an Object containing a two-dimensional array.
// The first dimension represents the list of topic IDs.
// The second dimension represents the values associated with the topic IDs.
var
Data : OleVariant;
begin
//Create an array to return the topics and their values
//note:The Bounds parameter must contain an even number of values, where each pair of values specifies the upper and lower bounds of one dimension of the array.
Data:=VarArrayCreate([0, 1, 0, 0], VT_VARIANT);
Data[0,0]:=MyTopicId;
Data[1,0]:=GetTime();
if Main.Form1.CheckBoxExtraInfo.Checked then Main.Form1.ListBoxInfo.Items.Add('Excel called RefreshData. Returning TopicId: '+IntToStr(Data[0,0])+' and Value: '+Data[1,0]);
TopicCount:=1;
// RefreshTimer.Enabled:=true;
//Result:=PSafeArray(VarArrayAsPSafeArray(Data));
Result:=PSafeArray(TVarData(Data).VArray);
end;
I'm not sure about this part:
Result:=PSafeArray(TVarData(Data).VArray);
But it could be any part of the code.
Excel just doesn't show any result in the cell containing the rtd() function call. I did manage to get a result into the cell the first time Excel calls my "ConnectData" function that simple returns a string instead of a PSafeArray (although the very first call to that function fails to produce a result (N/A). Only after changing the Topic in the RTD() call it displays a result (one time only))
I based the code on an example in C# from https://blog.learningtree.com/excel-creating-rtd-server-c/
Can anyone point me in the right direction?
OleVariant owns the data it holds, and will release that data when itself goes out of scope. So you are returning an invalid PSafeArray pointer to Excel. You need to either:
release ownership of the array pointer before returning it:
function TRtdServer.RefreshData(var TopicCount: Integer): PSafeArray;
var
Data : OleVariant;
begin
...
Result := PSafeArray(TVarData(Data).VArray);
TVarData(Data).VArray = nil; // <-- add this
end;
use SafeArrayCopy() to make a copy of the array, and then return the copy:
uses
..., ActiveX;
function TRtdServer.RefreshData(var TopicCount: Integer): PSafeArray;
var
Data : OleVariant;
begin
...
OleCheck(
SafeArrayCopy(
PSafeArray(TVarData(Data).VArray),
Result
)
);
end;

Sharepoint. External Content Types. Passing values to stored procedure

I have simple stored procedure, that takes couple parameters and updates table.
How to pass parameters via BDC?
For example, to execute stored procedure, that selects rows and takes one param, code below.
BdcService bdcservice = SPFarm.Local.Services.GetValue<BdcService>();
IMetadataCatalog catalog = bdcservice.GetDatabaseBackedMetadataCatalog(SPServiceContext.Current);
// entity.GetLobSystem().GetLobSystemInstances()[0].Value;
IEntity entity = catalog.GetEntity(Utils.EntityNamespace, "GetMessage");
ILobSystemInstance lobSystemInstance = entity.GetLobSystem().GetLobSystemInstances()[0].Value;
IFilterCollection filters = entity.GetDefaultFinderFilters();
ComparisonFilter filter = (ComparisonFilter)filters[0];
filter.Value = code;
IEntityInstanceEnumerator enumerator = entity.FindFiltered(filters, lobSystemInstance);
DataTable result = entity.Catalog.Helper.CreateDataTable(enumerator);
DataTable result contains selected rows.
But how to pass couple parameters to Update procedure?
BdcService bdcservice = SPFarm.Local.Services.GetValue<BdcService>();
IMetadataCatalog catalog = bdcservice.GetDatabaseBackedMetadataCatalog(SPServiceContext.Current);
// entity.GetLobSystem().GetLobSystemInstances()[0].Value;
IEntity entity = catalog.GetEntity(Utils.EntityNamespace, "ContractAdd");
ILobSystemInstance lobSystemInstance = entity.GetLobSystem().GetLobSystemInstances()[0].Value;
// entity.ExecuteScalar();
entity has method "ExecuteScalar", but how to pass params via this method?

Calling a field name in a Struct in Matlab?

I am passing in a variable name MetabMapString to the function spectroscopy(). MetabMapString is the name of the field I want to call. But It seems as if Matlab is thiking that MetabMapString is the name of the fields cause it returns that there is no field names MetabMapString. I have included some code. Is there a way to get this to work?
function spectroscopy(MetabMapString)
spect = importdata(spectLCMI);
n = length(spect.MetabMapString);
Row = spect.Row;
Col = spect.Col;
spectOrig = spect.MetabMapString;
...
end
Here is the error
??? Reference to non-existent field 'MetabMapString'.
Error in ==> SpectDraw>spectroscopy at 1165
n = length(spect.MetabMapString);
It should be:
n = length(spect.(MetabMapString));
That should work. Same in all other places where you're using a variable which contains a string as a field name of a struct or MATLAB class, or as a method name of a class:
spectOrig = spect.(MetabMapString);

Resources