When working with a list of items (using RangeStart and RangeEnd), how to you identify the last record?
The examples I've seen so far use IF and MERGESEQ to check for the first item or use SET to set a value to be checked later.
If I want to write some text when on the very last item, what will it look like?
{ IF { MERGESEQ } = "?" "Sign here" "" }
Related
I have created a group in the flexilayout studio to extract Invoice date. I was able to capture the value using "Date" element however for some invoices I had to capture using "Character String" element. How to provide the condition in the "Output expression" of Block element to check for any one of the values?
The best approach here is to create a new "Region"-type element. Then use the following code:
if (DateElement.IsFound) Then {
RSA: DateElement.Rect; // if date is found, then set this element region to date region
} else if (CharacterStringElement.IsFound) Then {
RSA: CharacterStringElement.Rect; // if char string is found, the set its region
} else {
DontFind; // don't find anything if everything failed
}
After this, you use this region element as a source for your "InvoiceDate" block.
This page describes how to retrieve an item, (immediate) child items and searching in Sitecore9 using the RESTful API (via PostMan).
What it doesn't appear to say is how to combine those queries.
I would like to search the children of an item which is specified by path. So, currently, I have this returning an item:
GET https://{{sitecorehost}}/sitecore/api/ssc/aggregate/content/Items('{{sitecorehome}}/banners-tests')?sc_apikey={{sitecore-master-apikey}}
I also have this returning the child items of that item:
GET https://{{sitecorehost}}/sitecore/api/ssc/aggregate/content/Items('{{sitecorehome}}/banners-tests/Subcontent/Image and Texts')/Children?sc_apikey={{sitecore-master-apikey}}
However, because the children are not immediate children - they are two levels down at /Subcontent/Image and Texts - I cannot request them. Yes, I could search for them, but then any items would come back with the matching criteria and I only want to search items under that particular path.
I would like something which, I imagine, would look something like this:
GET https://{{sitecorehost}}/sitecore/api/ssc/aggregate/content/Items?sc_apikey={{sitecore-master-apikey}}&$filter=Name eq 'banner' and Path eq 'banners-tests'
Or perhaps this:
GET https://{{sitecorehost}}/sitecore/api/ssc/aggregate/content/Items('{{sitecorehome}}/banners-tests')/Children?sc_apikey={{sitecore-master-apikey}}&$filter=Name eq 'banner'
But these do not work.
#Matt We can do filtering based on the item path. For example, considering item path as :
'sitecore/content/home/tenant1/Subcontent/Image and Texts/neededitem' - the one needed
'sitecore/content/home/tenant1/Subcontent/Image and
Texts/item1/neededitem/notneededitem' - the one we need to exclude
since '/' is not a valid character in the Sitecore item name and indicates the children of the needed item.
Hence, it can be used as a filter in javascript.
So we can split by 'Image and Texts' and then find the items.
For example, consider an array of results and let us say object with a collection of items is items and item path of each item is denoted by Path(let's say, this can be some other property as well) property
let items = [{
Path: 'sitecore/content/home/tenant1/Subcontent/Image and Texts/neededitem',
anotherProperty: 'text-val1'
}, {
Path: 'sitecore/content/home/tenant1/Subcontent/Image and Texts/item1/neededitem/notneededitem',
anotherProperty: 'text-val2'
}];
const results = items.filter(item => {
const splittedPath = item.Path.split('Image and Texts');
if (splittedPath[1].split("/").length <= 2) {
return item;
}
});
console.log(results);
In case your SSC controller (C#) is custom one and having access to Sitecore Context object or Sitecore APIs then the GetChildren() method of Item class will bring children of first level only.
I hope this helps.
I was wondering how can i POST in a single request (without fetching results for the given attribute) a pretty simple record to an Algolia Index without creating repeated instances.
e.g:
category: {
name: String // This should be unique
}
There isn't such "addObject if not exists" feature based on the record content but if you use the category name as the objectID of your record; the second time you'll add the object, it will just replace the previous instance.
{
objectID: "mycategoryname",
moreattributes: "if needed",
[...]
}
Would that work?
From the docs, I have this similar code:
$collection = $collection->each(function ($item, $key) {
if (/* some condition */) {
//I want to remove this specific item:
$item->delete(); //This is not working for me
//return false;
}
});
So given a certain condition, I want to delete that specific Item.
I use the ->delete() method but it doesn't work since I get the same count() results.
How do I remove those specific items?
I have tried ->pop() but it does delete the items from the database! I just want to remove those items only in the collection. :-P
Solution As suggested by Pawel Bieszczad, I tried with ->filter() function (There're so many nice methods that my mind got blocked) so I got it working like this:
$filtered = $projects->filter(function($item)use($app,$lastyear,$thisyear){
if(some_condition){
return $item; //I do want to keep this item in the collection.
}else{
//Don't do anything. Remove item. I don't want to keep this item in the collection.
}
});
You want to use the filter method
I would like to learn how to display the name of the month before the current month in a Word 2003 document. I have tried over and over again to follow the instructions I found on the link below, but no matter what I try I get one of several errors, something about syntax or picture switches that I don't understand. I have tried searching and I think I just don't know how to actually put the code into MS Word. Would anyone be willing to help me take this code from your forum and enter it into my document?
Thank you!
How do I display the next month in a Microsoft Word field?
The trouble with field coding is that there are a number of locale-related dependencies. That is one possible reason why you have been unable to make the suggestions in the links you mention work. Another reason is that one suggestion there cannot possibly have worked :-)
I suggest that you try to insert the following nested field in your document, and see if that works:
{ QUOTE "2013-{ = { DATE \#M } - 1 \#00;;'12' }-01" \#MMMM }
Some notes:
- use ctrl-F9 to insert a pair of the special field code braces {} (you can't just type them on the keyboard)
- you can toggle between "field code view" and "field result view" using alt-F9. You may need to do that as you proceed
- these fields will not automatically update. To ensure that the result is for the current date, select the nested field and click F9
To insert the nested field:
- click F9. You should see
{ }
click between the braces, and type
QUOTE "2013--01" \#MMMM
so you see
{ QUOTE "2013--01" \#MMMM }
click between the two "--" and click ctrl-F9 again so you see
{ QUOTE "2013-{ }-01" \#MMMM }
click between the new { } and type
= - 1 \#0;;'12'
so you see
{ QUOTE "2013-{ = - 1 \#00;;'12' }-01" \#MMMM }
click after the ' = ' and click ctrl-F9 again so you see
{ QUOTE "2013-{ = { } - 1 \#0;;'12' }-01" \#MMMM }
click between the new { } and type
DATE \#M
so you see
{ QUOTE "2013-{ = { DATE \#M } - 1 \#00;;'12' }-01" \#MMMM }
Then select the nested field, clcik F9,and click alt-F9 as necessary to display the result.
This approach probably differs from what you have seen before because
it doesn't use a nested IF to generate the correct month
it uses a YYYY-MM-DD format to generate a date that can be used to extract the month name. That's because using formats such as DD/MM/YYYY depend on the locale (i.e. they may work if the date format is DD/MM/YYYY but not if it's MM/DD/YYYY. As far as I know, YYYY-MM-DD is either locale-independent, or as locale-independent as it gets.