<script runat="server">
var id = 1234;
var getName = "%globals_get_text%"; // "Lun"
var name= "%" + "globals_asset_name:" + id + "%"; // "Lunch"
print(name.indexOf(getName)); // Errr: I am getting -1
</script>
Hi, I am checking if a short string is included in another long string with above code, but I am getting wrong result from the code. getName(Lun) should be included in name(Lunch) but it says it is not.
I tried with normal javascript and it works well. Should I need to do any other thing to complete this comparison?
var result = '%result_list%'; // '["1112","1113"],["1112","1114"],'
var getName = "%globals_get_text%";
var result_list = result.split(',');
var list = [];
for(var i = 0; i < result_list.length; i++){
var id = result_list[i].replace(/[^0-9]/g, '');
if(id && list.indexOf(id) === -1) {
list.push(id);
}
}
for(var i = 0; i < list.length; i++){
var id = list[i];
var getName = "%globals_get_text%"; // "Lun"
var name= "%" + "globals_asset_name:" + id + "%"; // "Lunch"
print(name.indexOf(getName)); // Errr: I am getting -1
}
what I am trying to build is
In a project, multiple students are participated. And there are like 10 projects and about 40 students are participated to each projects. I used search asset to find out all students who participated the project.
var result = '%result_list%'; // '["1112","1113"],["1112","1114"],'
var result_list = result.split(',');
var list = [];
for(var i = 0; i < result_list.length; i++){
var id = result_list[i].replace(/[^0-9]/g, '');
if(id && list.indexOf(id) === -1) {
list.push(id);
}
}
Students are standard page asset, which is related asset(metadata) to project. Search Page asset searches all the projects and returns all student list from project’s metadata field.
for(var i = 0; i < list.length; i++){
var id = list[i];
var getName = "%globals_get_text%"; // "Lun"
var name= "%" + "globals_asset_name:" + id + "%"; // "Lunch"
print(name.indexOf(getName)); // Errr: I am getting -1
}
Above part, we have list of asset id of students. We should be able to filter by name from the list.
var getName = “%globals_get_text%”; <-- name user put on the filter
var name= “%” + “globals_asset_name:” + id + “%”; <-- We get the asset name using keyword
If name on the filter is included to any name in the list, print something
Try doing something like this instead where you bring the “if” logic into the keyword instead of JS:
print("%" + "globals_asset_name:" + id + "^contains:{globals_get_text}:yes:no%");
But you could also try and print the actual asset’s name in the search results, so that it’s part of the array that %result_list% produces, that way you can do it all in JS.