How to get asset name and the attributes of the asset when we know Asset ID in WCS - webcenter

I am able to get Asset Id and Asset type present in Recommendation asset. However once I get both of them . I am unable to get asset name attribute and the user-defined attributes of the asset using either Asset Id or on using both both Asset Id and Asset type. Below is the code:
So how do I get asset name and the user-defined attributes of the asset ?
<commercecontext:getrecommendations
collection='<%=ics.GetVar("op_rec_men_name")%>'
maxcount="10" listvarname="list_allassets"/>
<br/> Asset Details:
<ics:listloop listname="list_allassets">
<ics:listget listname="list_allassets" fieldname="assetid"
output="op_assetid"/>
Asset ID : <%=ics.GetVar("op_assetid")%> <br/>
<ics:listget listname="list_allassets" fieldname="assettype"
output="op_assettype"/>
Asset Type: <%=ics.GetVar("op_assettype")%> <br/>
<%-- Using Asset Id and Asset Type values and defining "setasset"--%>
<assetset:setasset name="msd" type='<%=ics.GetVar("op_assettype")%>'
id='<%=ics.GetVar("op_assetid")%>'/>
<%-- Trying to get value of user-defined attribute "Page_FS2_Int_SV"
corresponding to the above Asset Id and Asset Type. This part of code
is not working from here --%>
<assetset:getattributevalues name="msd" attribute="Page_FS2_Int_SV"
listvarname="list_int_sv" />
Page_FS2_Int_SV: <string:stream list="list_int_sv"
column="namevalue"/>
<br/>
<%-- Tried value as "name", "Name", "assetname" but did not work --%>
<assetset:getattributevalues name="msd" attribute="name"
listvarname="list_asset_name" />
Asset Name: <string:stream list="list_asset_name" column="namevalue"/>
<br/>
</ics:listloop>
Expected Output: Asset Name and values of user-defined attributes of the Asset
I am successfully getting Asset Id and Asset Type but not Asset Name and values of user-defined attributes of the Asset.
Query : So how do I get Asset Name and values of user-defined attributes of the Asset ?

You need to specify typename attribute in assetset:getattributevalues tag. You can debug your code to verify the same, just insert:
<ics:clearerrno/>
<assetset:getattributevalues .....>
<ics:geterrno/>
This should print error number which tells you that you're missing to include an attribute in the tag!

Related

Get company company's currency_id in qweb report Odoo 10

I need to use company currency id in qweb report. i tried below codes, but nothing worked. Getting an error:
AttributeError: 'NoneType' object has no attribute 'id'
<span t-esc="company.id"/>
<span t-esc="o.company.id"/>
If o is the name of your record, which the report is printed for, and if the guideline from odoo was followed (which means the company is saved under the field company_id), then it should be:
<!-- example for currency name -->
<span t-field="o.company_id.currency_id.name" />
<!-- example for currency symbol -->
<span t-field="o.company_id.currency_id.symbol" />

Sorting New Grid Column in Sylius Error

I'm trying to get sorting to work on my new column in the Sylius admin 'Products' page, on the product grid. The column is mainTaxon, and I've gotten it to display correctly by adding a section to src/Sylius/Bundle/AdminBundle/Resources/config/grids/product.yml
under 'fields':
mainTaxon:
type: twig
label: "Main Taxon"
sortable: ~
options:
template: #SyliusAdmin/Product/Grid/Field/mainTaxon.html.twig
from the mainTaxon tempate I then render the main taxon if there is one, or else just a space character.
{% if data %}
<a href="/admin/taxons/{{ data.id }}/edit">
{{ data.name }}
</a>
{% else %}
{% endif %}
This all works great for displaying the column with the main taxons. Unfortunately, as soon as I click on sort I get the following error:
An exception has been thrown during the rendering of a template
("Notice: Undefined index: mainTaxon") in
SyliusAdminBundle:Grid:_default.html.twig at line 41. 500 Internal
Server Error - Twig_Error_Runtime
The line in the file that the error references is:
{% for row in data %}
This is the row loop that generates the entire grid for the product page. It seems to be having trouble before it ever gets to rendering the cell (td) that contains the mainTaxon, presumably because there is an array somewhere that I don't know about, which is missing the index for the extra category? Just a guess, insight appreciate!
EDIT:
I've done some further digging into this. Documentation on grid editing has been committed to Sylius since I asked this question: http://docs.sylius.org/en/latest/customization/grid.html, though unfortunately it still does not address adding new fields.
I've taken a look at the Product.orm.xml file that maps the product ORM, and see that the mainTaxon field is mapped as follows:
<many-to-one field="mainTaxon" target-entity="Sylius\Component\Taxonomy\Model\TaxonInterface">
<join-column name="main_taxon_id" referenced-column-name="id" nullable="true" />
</many-to-one>
I think the issue must be that when a sort is performed a new query must be run to pull the product data from the database again, resorted. Clearly this mapping on the main_taxon_id column is entering the sort query incorrectly, presumably because it is a foreign key. I'm uncertain if foreign keys are not supported by the sorting functionality yet and this should be planned for the future, or whether there's something further I need to do to get this working.

Visual Basic: Set attribute of web element whitout ID

HTML:
<input type="text" size="15" maxlength="79" value="" name="username">
As you can see, no ID. The HTML above is a textbox that i want to auto fill in whit my value as soon as i start the webpage whit my code.
this is what i found:
WebBrowser1.Document.Forms(0).GetElementsByTagName("username")(0).SetAttribute("value", (Text))
But whit this i get the error:
Value of '0' is not valid for 'index'. 'index' should be between 0 and -1.
Parameter name: index
What am i doing wrong?
This isn't going to find any elements:
WebBrowser1.Document.Forms(0).GetElementsByTagName("username")
"Tag name" doesn't mean the value of the name attribute, it means the name of the HTML tag itself. Like this:
WebBrowser1.Document.Forms(0).GetElementsByTagName("input")
Of course, this is likely to return multiple matched elements, so you'll need to further identify which one you want to modify. The point being that you should do some error checking to make sure that it finds anything, because trying to index an empty collection will result in an error:
WebBrowser1.Document.Forms(0).GetElementsByTagName("username")(0)
Since the collection has no elements, there is nothing at index 0.
May be u could try
Me.WebBrowser1.Document.GetElementByName("username").SetAttribute("Value", txtUsername.Text)

options_from_collection_for_select Definition

I have just read the Rails API definition for option_from_collection_for_select.
Returns a string of option tags that have been compiled by iterating over the collection and assigning the result of a call to the value_method as the option value and the text_method as the option text
Now I am very new to rails so was wondering if someone could break this down into smaller chunks and explain what is happening, dumb it down if you will, the explanation is very high level (well for me at the moment)
Thank you
Using the example from the Ruby on Rails API, let's assume you have a Person model that has an id attribute and a name attribute.
Say you have a form that creates a new project and assigns it to a person. Maybe you want to have a drop down select for what person you're assigning this project to. You could use options_from_collection_for_select for something like this.
<%= f.label :person, "Assigned Person" %>
<%= f.select(:person, options_from_collection_for_select(#people, "id", "name") )
(f by the way would be referring to the #project variable for our example form here.)
What this would do is create an option in your select drop-down for each person contained in the instance variable #people. Each of the <option> tags would have the id of that person assigned to its value attribute, and the text for that option would be the person's name.
So if your #people variable contained [#<Person id: 1, name: "Brock Sampson">, #<Person id: 2, name: "Byron Orpheus">], you would get HTML output like this:
<label for="project_person">Assigned person"</label>
<select id="project_person" name="project[person]">
<option value="1">Brock Sampson</option>
<option value="2">Byron Orpheus</option>
</select>
Does that make more sense?

Rails 3 Select box posts a blank variable but the HTML is well-formed

I'm having problems with the select tag in my view.
First of all I'm using Rails 3.1.1 and Ruby 1.9.2 p290
The model is a Consumable which has a name, supplier, reorder number, type and associated printer models that it is compatible with.
The field that isn't validating correctly is type which is fed values from an array in the Consumable model and the validation should be against inclusion of one of the elements of the array.
In the model, I define the field's validation like so
TYPES = [ "REM", "REM-HICAP", "OEM", "OEM-HICAP" ]
validates :type, inclusion: TYPES
In the view (form partial for Consumable) I've created the select tag thusly
<div class="field">
<%= f.label "Type" %><br />
<%= f.select :type, Consumable::TYPES, prompt: 'Select a type...',
:selected => params[:type] %>
</div>
The drop-down box is creating well-formed HTML which looks like this
<div class="field">
<label for="consumable_Type">Type</label><br />
<select id="consumable_type" name="consumable[type]">
<option value="">Select a type...</option>
<option value="REM">REM</option>
<option value="REM-HICAP">REM-HICAP</option>
<option value="OEM">OEM</option>
<option value="OEM-HICAP">OEM-HICAP</option>
</select>
</div>
When I post the form this is the debug information
---
utf8: ?
_method: put
authenticity_token: nZZ9MastYswVCDrvAbgVLTUWqSRZLVrvRLmxOqPYk7I=
consumable:
description: Black Toner
supplier_id: '1'
reorder_no: '123456'
type: OEM
printer_model_ids:
- '1'
- '3'
commit: Update Consumable
action: update
controller: consumables
id: '1'
As is evident by the debug info, type is set correctly with a value from the select box (a string) and type in the model is a string. The form instead shows the validation error "Type is not included in the list" and if I remove the validation the database shows a nil value for the type field.
At what point is the validation applied to the form, does the controller trigger it by attempting to save the object?
I have used the same method of validating a drop-down box in the depot application in Agile Web Development with Rails 4th Edition with essentially the same code but a different name for the array and it works correctly.
I have just tested the same validation in the depot application and it works on this same workstation, so I would count out setup inconsistencies.
Thanks
I finally discovered my error: Type is protected in Rails and changing my variable name to Kind make it work correctly.