Getting EntryNode values (multi occurences attribute) - ibm-information-server

How do I get values of Multi-Occurrences Attribute?
I have found a partial solution here, but am not clear with getting EntryNode.
https://www.ibm.com/support/knowledgecenter/en/SSWSR9_11.6.0/com.ibm.pim.app.doc/code/pimscript/pim_ref_writevalueruleformultiatt.html

This is the part that returns always the same code:
rawCode=item.getEntryRelationshipAttrib("Product Master Catalog Spec/Raw Materials Details/Code");
That is because it always returns the first occurrence.
 
I think your code should look something like this:
 
pnode = entrynode.getEntryNodeParent(); 
attribCode = pnode.getEntryNode("/Code").getEntryNodeValue();
//This returns the path with the # and the correct order.
attribCodePath = pnode.getEntryNode("/Code").getEntryNodeExactPath();
rawCode=item.getEntryRelationshipAttrib(attribCodePath);
rawmatCode = rawCode[1];
var rawCatalog = getCtgByName("Raw Material Catalog") ;
rawMatItem = rawCatalog.getCtgItemByPrimaryKey(rawmatCode);
rawMatCost = rawMatItem.getEntryAttrib("Raw Material Details Spec/Cost") ;
 
attribQty = pnode.getEntryNode("/Qty").getEntryNodeValue();
res=attribQty*rawMatCost;

Related

Finding object in a class by attribute value

How do you grab an object based on its attribute (in this case, an ID that is assigned to it)? Here is an example of the code that I'm currently working on.
Ped = {} -- Ped class.
Ped.__index = Ped
gPedID = 0
gPedAdditionalID = "Shop"
function Ped.create(_type, _skin, _x, _y, _z)
local _ped = {}
setmetatable(_ped,Ped)
_ped.oType = _type
_ped.pedElement = createPed(_skin, _x, _y, _z)
_ped.ID = gPedID
gPedID = gPedID + 1
return _ped
end
function pedID(player, command)
-- code to grab the object based on the object.ID
end
I've tried to make a table that references the object, i.e:
generictable[_ped.ID] = _ped
But to no avail, I'm guessing the reason why is because it only copies the address, not the actual reference.
Help is much appreciated, thanks!

EPPlus chart(pie,barchart) selected(B2,B36,B38) .. etc excel cells

I have similar to the link below problem.
EPPlus chart from list of single excel cells. How?
I tried the code but it shows it twice in the chart. For example:
This code show excel chart -> select data-> horizontal(category) axis labels tab you show 100,100,300,600 write. What is the reason for this? The chart is written twice the first data I did not find a solution to the problem.
I think you just discovered a bug with EPPlus. Shame on me for not noticing that with that post you reference. It seems that when using the Excel union range selector (the cell names separated by commas) the iterator for the ExcelRange class returns a double reference to the first cell, in this case B2.
A work around would be to use the other overload for Series.Add which will take two string ranges. Here is a unit test that show the problem and the workaround:
[TestMethod]
public void Chart_From_Cell_Union_Selector_Bug_Test()
{
var existingFile = new FileInfo(#"c:\temp\Chart_From_Cell_Union_Selector_Bug_Test.xlsx");
if (existingFile.Exists)
existingFile.Delete();
using (var pck = new ExcelPackage(existingFile))
{
var myWorkSheet = pck.Workbook.Worksheets.Add("Content");
var ExcelWorksheet = pck.Workbook.Worksheets.Add("Chart");
//Some data
myWorkSheet.Cells["A1"].Value = "A";
myWorkSheet.Cells["A2"].Value = 100; myWorkSheet.Cells["A3"].Value = 400; myWorkSheet.Cells["A4"].Value = 200; myWorkSheet.Cells["A5"].Value = 300; myWorkSheet.Cells["A6"].Value = 600; myWorkSheet.Cells["A7"].Value = 500;
myWorkSheet.Cells["B1"].Value = "B";
myWorkSheet.Cells["B2"].Value = 300; myWorkSheet.Cells["B3"].Value = 200; myWorkSheet.Cells["B4"].Value = 1000; myWorkSheet.Cells["B5"].Value = 600; myWorkSheet.Cells["B6"].Value = 500; myWorkSheet.Cells["B7"].Value = 200;
//Pie chart shows with EXTRA B2 entry due to problem with ExcelRange Enumerator
ExcelRange values = myWorkSheet.Cells["B2,B4,B6"]; //when the iterator is evaluated it will return the first cell twice: "B2,B2,B4,B6"
ExcelRange xvalues = myWorkSheet.Cells["A2,A4,A6"]; //when the iterator is evaluated it will return the first cell twice: "A2,A2,A4,A6"
var chartBug = ExcelWorksheet.Drawings.AddChart("Chart BAD", eChartType.Pie);
chartBug.Series.Add(values, xvalues);
chartBug.Title.Text = "Using ExcelRange";
//Pie chart shows correctly when using string addresses and avoiding ExcelRange
var chartGood = ExcelWorksheet.Drawings.AddChart("Chart GOOD", eChartType.Pie);
chartGood.SetPosition(10, 0, 0, 0);
chartGood.Series.Add("Content!B2,Content!B4,Content!B6", "Content!A2,Content!A4,Content!A6");
chartGood.Title.Text = "Using String References";
pck.Save();
}
}
Here is the output:
I will post it as an issue on their codeplex page to see if they can get it fixed for the next release.

Unable to add data in archive table in Entity Framework

I wrote the code to update my table (SecurityQuestionAnswer) with new security password questions and move to old questions to another table (SecurityQuestionAnswersArchives). Total no of security questions is 3. I am able to update the current table, but when I add the same rows to history table, it shows weird data: only two records are added instead of 3 and the data is also duplicated. My code is as follows:
if (oldQuestions.Any())
{
var oldquestionstoarchivelist = new List<SecurityQuestionAnswersArchives>();
var oldquestionstoarchive =new SecurityQuestionAnswersArchives();
for (int i = 0; i < 3; i++)
{
oldquestionstoarchive.Id = oldQuestions[i].Id;
oldquestionstoarchive.SecurityQuestionId = oldQuestions[i].SecurityQuestionId;
oldquestionstoarchive.Answer = oldQuestions[i].Answer;
oldquestionstoarchive.UpdateDate = oldQuestions[i].UpdateDate;
oldquestionstoarchive.IpAddress = oldQuestions[i].IpAddress;
oldquestionstoarchive.SecurityQuestion = oldQuestions[i].SecurityQuestion;
oldquestionstoarchive.User = oldQuestions[i].User;
oldquestionstoarchivelist.Add(oldquestionstoarchive);
}
user.SecurityQuestionAnswersArchives = oldquestionstoarchivelist;
//await Store.UpdateAsync(user);
_dbContext.ArchiveSecurityQuestionAnswers.AddRange(oldquestionstoarchivelist);
_dbContext.SecurityQuestionAnswers.RemoveRange(oldQuestions);
await _dbContext.SaveChangesAsync();
oldquestionstoarchivelist.Clear();
}
UPDATE 1
The loop looks fine, It iterates three times(0,1,2), which is expected. First issue is with AddRange function to which I was passing a list , but it takes an IEnumerable input, I rectified it using following code.
IEnumerable<SecurityQuestionAnswersArchives> finalArchiveses = oldquestionstoarchivelist;
_dbContext.ArchiveSecurityQuestionAnswers.AddRange(finalArchiveses);
The other issue is duplicate data , which I am unable to figure out where the issue is. Please help me in finding this out.
Your help is much appreciated !
Got it ! Just sharing in case anybody has same issue.
The problem was with initialization at wrong place. I moved
var oldquestionstoarchive =new SecurityQuestionAnswersArchives();
in side the Forloop, now the variable will hold the unique values over each iteration.
var oldquestionstoarchivelist = new List<SecurityQuestionAnswersArchives>();
for (int i = 0; i < 3; i++)
{
var oldquestionstoarchive = new SecurityQuestionAnswersArchives();
oldquestionstoarchive.SecurityQuestionId = oldQuestions[i].SecurityQuestionId;
oldquestionstoarchive.Answer = oldQuestions[i].Answer;
oldquestionstoarchive.UpdateDate = oldQuestions[i].UpdateDate;
oldquestionstoarchive.IpAddress = oldQuestions[i].IpAddress;
oldquestionstoarchive.SecurityQuestion = oldQuestions[i].SecurityQuestion;
oldquestionstoarchive.User = oldQuestions[i].User;
oldquestionstoarchivelist.Add(oldquestionstoarchive);
}

Best way to check if variable is part of collection of enums?

I'm currently trying to port some Specman code that takes certain actions based on whether a variable is part of an enumeration. In Specman the code looks something like this:
define COMP_STATES do_add, do_sub;
define WAIT_STATES wait_X, wait_Y;
defube RUN_STATES run_X, run_Y;
type my_states : [
do_add = 3'b000;
do_sub = 3'b001;
wait_X = 3'b010;
wait_Y = 3'b011;
run_X = 3'b100;
run_Y = 3'b101;
] (bits:3);
and then later:
if(state in [COMP_STATES, RUN_STATES]){
/* DO STUFF */
} else if(state in [WAIT_STATES]){
/* DO STUFF */
}
I now would like to do this in SystemVerilog but have hit a little bit of a snag. My currently best approach uses arrays:
my_state which_state[$] = {`COMP_STATES, `RUN_STATES};
int indexes[$] = which_state.get_index( index ) where ( index == state );
int num_indexes = indexes.size(); //If state doesn't exist in my_state then the returned array of indexes will be empty.
if(num_indexes > 0) begin /* DO STUFF */ end
But there has to be a more elegant and concise way? find_first_index comes to mind but I couldn't find what it would return in case no match was found.
There are a couple of ways you could do this. If you can depend on the encoding, then you can define your collection with a wildcard and use the wildcard equality operator or inside operator
let COMP_STATES = 3'b00?; // or parameter COMP_STATES = 3'b00?;
let RUN_STATES = 3'b01?; // or parameter RUN_STATES = 3'b01?;
let WAIT_STATES = 3'b10?; // or parameter WAIT_STATES = 3'b10?;
if (my_states inside {COMP_STATES,RUN_STATES})
...
else if (my_state ==? WAIT_STATES)
...
or you could just create an expression
module top;
enum bit [2:0] {
do_add = 3'b000,
do_sub = 3'b001,
wait_X = 3'b010,
wait_Y = 3'b011,
run_X = 3'b100,
run_Y = 3'b101
} my_states;
let COMP_STATES = my_states inside {do_add, do_sub};
let WAIT_STATES = my_states inside {wait_X, wait_Y};
let RUN_STATES = my_states inside {run_X, run_Y};
initial repeat(20) begin
std::randomize(my_states);
$write (my_states.name());
case(1)
COMP_STATES, RUN_STATES:
$display("=comp,run");
WAIT_STATES:
$display("-wait");
endcase
end
endmodule
Finally, if you were starting from scratch, I would suggest looking at tagged unions and their corresponding pattern matching conditional statements

Xcode>Instruments>Automation>Mac: is there a way to use regular expression within Automation in Instruments

I am totally new to Instruments>Automation. Trying to test the internal app using Automation in Instruments.
Here is my problem:
Our app has the UI cells generated on the fly. There is no way to predict how many cells will be created and what name they will have. But, all of them will contain a certain string (like "Courses"). The question is - How, using Automation, find out if particular cell contain that string in its name?
You are able to get total cells count simply using "length" property.
var cellsCount = <YourUIATableViewObject>.cells().length;
UIALogger.logMessage("total cells count = " + cellCount);
After that you will be able to get cell properties and operate with them:
for (var i = 0; i < cellsCount; i ++)
{
var cellValue = <YourUIATableViewObject>.cells()[i].value();
var cellName = <YourUIATableViewObject>.cells()[i].name();
UIALogger.logMessage("Cell #"+i+" properties: cellValue ="+cellValue+"; cellName ="+cellName);
//Try to use match() or search() functions to find what you need.
if ( cellName.search("Courses") != -1 )
//if (cellValue.search("Courses") != -1 )
{
UIAlogger.logMessage("Cell #"+i+" contains 'Courses'");
}
else
{
UIAlogger.logMessage("Cell #"+i+" does not contain 'Courses'");
}
}
This JavaScript tutorial will help you: