Extract Product field for display on Test Case Search page - kiwi-tcms

I am extending Kiwi TCMS for my team and trying to display the Product on the Search Test Cases page. The Product is tied to the Category field and I am not sure how to extract that field within the testcases/static/js/seach.js file.
I have traced it back to jsonrpc.js but am missing something, not sure what it is I am not seeing.
I added the Product field in the search.html file and the data is moved 1 column to the left since the array does not contain the Product field. I have tried "product" and "product_id" in the columns[] section of search.js.
Thanks

I have traced it back to jsonrpc.js but am missing something, not sure what it is I am not seeing.
JSON RPC is a communications protocol. The spec is very simple, you can find it at https://www.jsonrpc.org/specification. The jsonRPC function in Kiwi TCMS is a wrapper for that.
FK relationship between models are represented with a field called ..._id. For example Category has a field product_id. At the same time the Product model has a reverse relationship to Category - this is something that the underlying web framework adds automatically. The field is called Product.category.
Checkout how to make queries here:
https://kiwitcms.readthedocs.io/en/latest/modules/tcms.rpc.api.html#module-tcms.rpc.api
If you have test_case.category_id then you can send another API request to Product.filter method filtering on the category field with the respective value.
Inside the browser console you can do something like:
jsonRPC('Product.filter', {category: 1630}, console.log)
and see the results you get.
I added the Product field in the search.html file and the data is moved 1 column to the left since the array does not contain the Product field. I have tried "product" and "product_id" in the columns[] section of search.js.
You will have to modify the entire page (which includes search, the callback, the HTML template and the function rendering the returned data) for this to work.
It sounds like either
you need more information shown in the search table: there isn't much space available, OTOH there is a filter per Product so if you teach users to filter by product everything they see will be related to that product so they won't need additional column for that information
you need a more flexible mechanism for extension - it is mostly doable and possible to design pages in Kiwi TCMS to be arbitrarily extensible, however we haven't thought in this direction and we need more information about the intended use-case to figure out the underlying architecture.
you can design an entirely separate search page, using the upstream code as your base. Then bundle that into a plugin and just install your plugin into Kiwi TCMS. That actually sounds like the best option in this case and you will have full control over that page, see https://kiwitcms.readthedocs.io/en/latest/plugins/index.html.

Related

WordPress : make categories automatically match according to external API Value

I'm managing a company website, where we have to display our products. We however do not want to handle the admin edit for this CPT, nor offer the ability to access to the form. But we have to read some product data form the admin edit page. All has to be created or updated via our CRM platform automatically.
For this matter, I already setup a CPT (wprc_pr) and registered 6 custom hierarchical terms: 1 generic for the types (wprc_pr_type) and 5 targeting each types available: wprc_pr_rb, wprc_pr_sp, wprc_pr_pe, wprc_pr_ce and wprc_pr_pr. All those taxonomies are required for filtering purposes (was the old way of working, maybe not the best, opened to suggestions here). We happen to come out with archive pages links looking like site.tld/generic/specific-parent/specific-child/ which is what is desired here.
I have a internal tool, nodeJS based, to batch create products from our CRM. The job is simple: get all products not yet pushed to the website, format a new post, push it to the WP REST API, wait for response, updated CRM data in consequence, and proceed to next product. Handle about 1600 products today on trialn each gone fine
The issue for now is that in order for me to put the correct terms to the new post, I have to compute for each product the generic type and specific type children.
I handled that by creating 6 files, one for each taxonomy. Each file is basically a giant JS object with the id from the CRM as a key, and the term id as a value. My script handles the category assertion like that:
wp_taxonomy = [jsTaxonomyMapper[crm_id1][crm_id2]] // or [] if not found
I have to say it is working pretty well, and that I could stop here. But I will have to take that computing to the wp_after_insert_post hook, in order to reaffect the post to the desired category on updated if something changed on the CRM.
Not quite difficult, but if I happen to add category on the CRM, I'll have to manually edit my mappers to add the new terms, and believe me that's a hassle.
Not waiting for a full solution here, but a way to work the thing. Maybe a way to computed those mappers and store their values in the options table maybe, or have a mapper class, I don't know at all.
Additional information:
Data from the CRM comes as integers (ids corresponding to a label) and the mappers today consist of 6 arrays (nested or not), about 600 total entries.
If you have something for me, or even suggestions to simplify the process, I'll go with it.
Thanks.
EDIT :
Went with another approach, see comment below.

Rename salesforce columns from API_name to field label

When you use salesforce data that has being exported through any API, tables you get have column names in their "API_Name" format. This differs a bit from their "Filed Label" format in which they are presented on salesforce's web UI (for example on reports).
You can find what API name corresponds to any of the columns (objects) in the salesforce object manager.
My question is: is there anywhere a dictionary to map API Names back to their Filed Labels? It will be very helpful to have in JSON or anything that can be used programmatically.
It's called "describe" data. It's available for whole object (label, plural label), fields (label, picklist value translations), names of related lists.
In Apex this is a good initial reading: https://developer.salesforce.com/docs/atlas.en-us.200.0.apexcode.meta/apexcode/apex_dynamic_describe_objects_understanding.htm and for fields: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_fields_describe.htm
If you're using REST API - make GET to /services/data/v55.0/sobjects/Account/describe for example.
Have a look at https://developer.salesforce.com/docs/atlas.en-us.uiapi.meta/uiapi/ui_api_quick_start.htm too. For example if you need to build your own UI for "dependent picklists" it can be painful to read it all from "describe", https://developer.salesforce.com/docs/atlas.en-us.uiapi.meta/uiapi/ui_api_features_records_dependent_picklist.htm is bit better. And when you fetch records via this API you get fields as object with visible label and raw value (useful when displaying dates, numbers for example)

Accessing CustomFieldDefinition metadata via tooling api

So, I've been attempting to gather picklist dependencies per Opportunity record type for my lightning components. I have been able to retrieve Standard Field dependencies by RecordType, but it the Tooling API will not return the custom field dependencies. Standard calls and queries will not work either, as they state that the field has no controlling value or dependency.
Given this information I suspected that there was a table that is hidden somewhere that contains the keys for the RecordType and FieldDefinition, hopefully with a nested Metadata object.
I found an Id in one of the parameters in the setup menu for a Record Type and Id.getSObjectType() on it. The table name is CustomFieldDefinition. However, it is not accessible via SOQL or the Tooling API.
Has anyone accessed this table? Or has anyone been able to retrieve the field-record type picklist dependencies on custom fields AND standard fields?Tooling API ResponseDebug Log with SObject Name
I think you're doing it wrong.
"Controlling field" would be another picklist or a checkbox for example, something you change during same edit action. If you have dependency to record type - in that sense it's not a controlling field. Sure, you change record type and picklist changes - but really everything would change, it should be a different page layout (different fields shown, marked readonly/required etc). There's a reason that record type change is not done on normal edit screen, you do it by clicking special link on detail view and then everything "explodes".
Have a look at "User Interface API" - set of tools meant to help your custom app (mobile? desktop?) steal recreate a normal page layout. This one might be especially useful: https://developer.salesforce.com/docs/atlas.en-us.uiapi.meta/uiapi/ui_api_resources_picklist_values_collection.htm
There's even a Trailhead: https://trailhead.salesforce.com/en/content/learn/modules/user-interface-api (skim through whole set but especially read last module)
And since you mentioned Lightning Components - are you aware of these ready tools:
https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.reference_ui_api
getPicklistValuesByRecordType
https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.reference_generate_record_input_create
or maybe you don't have to code it all and stuff like <lightning-record-edit-form> with recordtypeid passed to it will solve all your problems
Have a look, if I didn't give you a working solution then at least you have some keywords to Google around. If you're still stuck - try to post a code sample as new question?

SuiteCommerce Advanced - Show a custom record on the PDP

I am looking to create a feature whereby a User can download any available documents related to the item from a tab on the PDP.
So far I have created a custom record called Documentation (customrecord_documentation) containing the following fields:
Related item : custrecord_documentation_related_item
Type : custrecord_documentation_type
Document : custrecord_documentation_document
Description : custrecord_documentation_description
Related Item ID : custrecord_documentation_related_item_id
The functionality works fine on the backend of NetSuite where I can assign documents to an Inventory item. The stumbling block is trying to fetch the data to the front end of the SCA webstore.
Any help on the above would be much appreciated.
I've come at this a number of ways.
One way is to create a Suitelet that returns JSON of the document names and urls. The urls can be the real Netsuite urls or they can be the urls of your suitelet where you set up the suitelet to return the doc when accessed with action=doc&id=_docid_ query params.
Add a target <div id="relatedDocs"></div> to the item_details.tpl
In your ItemDetailsView's init_Plugins add
$.getJSON('app/site/hosting/scriptlet.nl...?action=availabledoc').
then(function(data){
var asHtml = format(data); //however you like
$("#relatedDocs").html(asHtml);
});
You can also go the whole module route. If you created a third party module DocsView then you would add DocsView as a child view to ItemDetailsView.
That's a little more involved so try the option above first to see if it fits your needs. The nice thing is you can just about ignore Backbone with this approach. You can make this a little more portable by using a service.ss instead of the suitelet. You can create your own ssp app for the function so you don't have to deal with SCAs url structure.
It's been a while, but you should be able to access the JSON data from within the related Backbone View class. From there, within the return context, output the value you're wanting to the PDP. Hopefully you're extending the original class and not overwriting / altering the core code :P.
The model associated with the PDP should hold all the JSON data you're looking for. Model.get('...') sort of syntax.
I'd recommend against Suitelets for this, as that's extra execution time, and is a bit slower.
I'm sure you know, but you need to set the documents to be available as public as well.
Hope this helps, thanks.

Outputting Stripe plan name via plan-ID using AngularJS ng-model two-way data binding

I am outputting form inputs on the final page of a checkout field, titled "Review & checkout"... on this page I display the plan the customer picked and the personal info they provided so far.
I have no problem showing fields like Name or Email, as the value inputted is being shown, as Angular displays whatever was in the value="" field of the input.
To display the subscription plan that the customer picked, it's trickier.
The value field is already being utilized to tell stripe which plan the customer should be charged for.
How can I get around this problem?
I am able to display the stripe-id for the plan but it is not user-friendly. They are id's like trad-2-5, trad-2-6, trad-2-7... so what I want to do is display a custom title when trad-2-5 is selected, and so on...
Any help is greatly appreciated!!Thanks
There are a couple of ways you could do this.
The really silly answer is that you can just create a map of plan ids to human-readable descriptions in the Angular controller code, then display that. This might be enough for what you want, but it's also pretty hacky, and not a lot of fun to maintain.
The less silly answer depends on where these plan ids are coming from. If they are coming from an endpoint on your server, which gets them from Stripe's plans endpoint, then you could also pass along the display name of the plan from that endpoint. If the plan id's are hard coded somewhere, or whitelisted, then this may not make sense. However, that display name is what will appear on the customer's invoice, and credit card statement, so it'd be nice to make it match up with what they see on the checkout page.

Resources