How to do empty list check in maximo anywhere - maximo-anywhere

I am getting few json response from service as "-##EmptyComplexField##-". Due to which screen crashes. How to do a proper empty check for complex feild in maximo anywhere. Please help with sample code.

We can do a empty check for list as below
if(list && list!="-##EmptyComplexField##-")

Not sure why you're getting this EmptyComplexField string down at your layer. Are you sure you've defined your multiplicity correctly on the OSLC Resources app for these new children objects?
if (/-or-many$/.test(complexAttribute.multiplicity)){
var attributeName = complexAttribute.remoteName;
if (!(attributeName in data)){
Are you making sure these complexattributes are set as requiredattributes on the view before you display it?

The most correct answer would be:
if (list && list != PlatformConstants.EMPTY_COMPLEX_FIELD) { ... }

Related

Hooks: processDatamap_preProcessFieldArray()

I am about porting an Extention from T3-6.2 to T3-7.6+
public function processDatamap_preProcessFieldArray(
&$fieldArray, $table, $id,
\TYPO3\CMS\Core\DataHandling\DataHandler &$pObj
) {
// t3_origuid is set? Yes, ist a Copy
if(isset($fieldArray['t3_origuid']) && $table=='mytable') {
$fieldArray['field1']++;
$fieldArray['filed2']--;
}
}
BUT:
To tell if it is a copy or not this needs the field 't3_origuid' in my record. It is not a standard field but if present it is filled by typo3.
Where does this filed come from? My I use this witout further problems?
If you know a hook/better way, (Slot, Signal?) to use in this case in T3 7.6+ please let me know.
Thanks a lot,
Christian.
This field is used by the sys extension workspace. If you change a tt_content element inside a workspace the original uid will be stored inside the field. So the changes,when they will be published, can be applied to the original element.

Some property object are null

I have a problem and of course i dont understand :) (and of course im french :)
On a table "evenement" i have a user linked.
And When i do :
$repository = $this->getDoctrine()->getManager()->getRepository('AppBundle:Evenement');
$evt = $repository->findOneById($evt);
dump($evt)
All is ok, i can read my evt, but when in profiler i click on a child object "user", all property are null (except id, usermail, mail, password)
and its the same thing when i do :
dump($evt->getUser());
Why all property are not filled ?
thank you and sorry for my english.
It's most probably Lazy Loading. Properties are not beeing read from DB unless you need them.
Try to do the following:
$repository = $this->getDoctrine()->getManager()->getRepository('AppBundle:Evenement');
$evt = $repository->findOneById($evt);
$evt->getUser()->getRoles(); // Ot whatever properties your user has.
dump($evt)
In this case, dump will show this property populated.

Using Linq, I get this: There is already an open DataReader associated with this Command which must be closed first

Here's what I'm trying to do:
IEnumerable<OfficeView> allOffices = GetAllOffices(); //this method also uses some linq query
foreach (var office in allOffices)
{
officeSales.Add(
new Tuple<int, decimal>(office.Id, GetSaleAmount(office.Id, someParams)));
}
public decimal GetAgentSaleAmount(int officeRef, someTypes someParams)
{
var q = ObjectQuery.Where
(i => i.officeId == officeRef && i.someOtherStuff == someParams)
.ToList();
return q.Sum(i => i.NetPrice);
}
I can't set MultipleActiveResultSets = true. Instead, as suggested here, I tried to do .ToList() before doing the summation, but got the same error. (and even if I wouldn't get the error, I think it would cause heavy load to fetch everything just to get the summation of one field)
I will be super thankful for any suggestion to solve this problem!
Update: The problem was all about GetAllOffices(), which returned IEnumerable (which leaves the DataReader open). I changed the first line as below and it worked. Thanks a lot guys :)
IEnumerable<OfficeView> allOffices = GetAllOffices().ToList();
Error said that reader is already opened, that means that you have run some query before which needs to close.
Write .ToList() to that linq query and do same for other queries too.
I think you are trying to do both adding and querying at the same time.You need to finish adding "Sale" object to "Sales" collection before trying to calculate the sales value.
In other words, you cannot query until the transaction is committed. Hope that helps.

SDL Tridion GetListKeywords using Anquilla Framework

I'm writing a GUI extension and using the Anquilla framework to get a list of Keywords within a Category. I'm obtaining an XML document for the list of keywords then working with that document within my extension.
My problem is that the returned XML doesn't contain the Keyword's 'Description' value. I have the Title and Key etc.
My original code looks like this:
var category = $models.getItem("CATEGORYTCMID:);
var list = category.getListKeywords();
list.getXml();
A typical node returned is this:
<tcm:Item ID="tcm:4-1749-1024"
Type="1024" Title="rate_one" Lock="0" IsRoot="true"
Modified="2012-12-17T23:01:59" FromPub="010 Schema"
Key="rate_one_value" IsAbstract="false"
CategoryTitle="TagSelector"
CategoryID="tcm:4-469-512" Icon="T1024L0P0"
Allow="268560384" Deny="96" IsNew="false"
Managed="1024"/></tcm:ListKeywords>
So I've tried using a Filter to give me additional column information:
var filter = new Tridion.ContentManager.ListFilter();
filter.columns = Tridion.Constants.ColumnFilter.EXTENDED;
var list = category.getListKeywords(filter);
Unfortunately this only gives the additional XML attributes:
IsShared="true" IsLocalized="false"
I'd really like the description value to be part of this XML without having to create a Keyword object from the XML. Is such a thing possible?
cough any ideas? cough
I'm afraid you'll have to load the Keyword itself to get the Description.
It's not used in any lists, so it's not returned in the XML.
You could always create a List Extender to add this information to the list, but try to be smart about it since this extender will execute everytime a GetList is called.
Won't save you from having to open every keyword in the list, but you'll be doing it server-side (with Core Service/NetTcp for instance) which will probably be easier and faster than opening each keyword with Anguilla.
In this instance I only need the one keyword, so I simply get it from the CMS. Getting an object in Anguilla is a bit weird, here's the code:
In your main code area:
var selectedKy = $models.getItem("TcmUriOfKeywordHere");
if (selectedKy.isLoaded()) {
p.selectedKy = selectedKy;
this.onselectedKyLoaded();
} else {
$evt.addEventHandler(selectedKy, "load", this.onselectedKyLoaded);
selectedKy.load();
}
It's worth noting how I store the keyword in the properties of the item, so I can obtain it in the onselectedKyLoaded function
The function called once the item is loaded
ContentBloom.ExampleGuiExtension.prototype.onselectedKyLoaded = function (event) {
var p = this.properties;
var selectedDescription = p.selectedKy.getDescription();
// do what you need to do with the description :)
};
I resolved this, thanks to the answer here: https://stackoverflow.com/a/12805939/1221032 - Cheers Nuno :)

runtime error in running asp.net application

Am running asp.net application with access database using gridview application..while running i got the run time error as
Object reference not set to an instance of an object.
Line 41: RadioButtonList rblGender = (RadioButtonList)GridView1.Rows[e.RowIndex].FindControl("rbGenderEdit");
Line 42:DropDownList ddlStatus = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlStatusEdit");
Line 43:SqlDataSource1.UpdateParameters["Sex"].DefaultValue = rblGender.SelectedValue;
Line 44:SqlDataSource1.UpdateParameters["MaritalStauts"].DefaultValue = ddlStatus.SelectedValue;
Line 45: }
I got this error specially in line 43..
So rblGender.SelectedValue or rblGender is null...
Perhaps the problen is with rblGender
Make assignment as follows:
RadioButtonList rblGender = GridView1.Rows[e.RowIndex].FindControl("rbGenderEdit") as RadioButtonList;
And then check for nullability:
if (rblGender == null)
{
//show error
}
RadioButtonList rblGender = (RadioButtonList)GridView1.Rows[e.RowIndex].TemplateControl.FindControl("rbGenderEdit");
if it is in template field.
it can't find rbGenderEdit.
When you have a runtime error like this one, you should use your debugger to actually see what is going on behind the scene. Just put your breakpoint at the line 43 for instance, run your program in debug mode and start investigate to see what object has a null reference and try to fix it.
For instance take a look at the line 41, rblGender might be null...
EDIT
You must check if the objects that you are manipulating are null, this is part of the defensive programming techniques.
In your example, as others have said you can do it this way:
if(rblGender == null) {
// If you are running your program with a console
// Otherwise you should display this anywhere you can or in a log file.
Console.WriteLine("rblGender is null");
}
else if(rblGender.SelectedValue == null) {
Console.WriteLine("rblGender.SelectedValue is null");
}
Run your program and check what is being written! This is not going to solve your problem, but it is just going to tell you where your null reference is which will help you figure out what should be fixed!
But as I said earlier you can also debug your program properly by putting a breakpoint (you know the red ball when you click on the side of the window) at the line 43, and then run your program in debug mode! When the runtime error will fireup you will be able to check whether rblGender or rblGender.SelectedValue is null.
Also, from a more general point of view, checking your object against null references will prevent your application from crashing suddenly by managing the case where an objet might have a null reference at any given time. For instance you can say:
if(my_object is null)
{
myValue = "default";
}
else
{
myValue = my_objet.getValue();
}
This is just an example it could be done in a better way, using exceptions (try/catch/finally) for instance but the general idea is: check against null references!

Resources