I have developed a lightning component modal popup to show on the opportunity page. There are two options Yes and No. On condition this lightning component is transferring the flow to one visualforce page or the other with the account id. How I can get the account id in the lightning component.
<aura:component implements="force:lightningQuickActionWithoutHeader">
Are you sure you want to proceed?
<div class="slds-align_absolute-center">
<lightning:button
label="No"
variant="destructive"
onclick="{!handleNo}"
></lightning:button>
<lightning:button label="Yes" onclick="{!c.handleYes}"></lightning:button>
</div>
</aura:component>
and the controller is
({
handleNo: function (component, event, helper) {
var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
url: "/apex/MyOtherVisualforce",
isredirect: "true"
});
urlEvent.fire();
},
handleYes: function (component, event, helper) {
var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
url: "/apex/MyVisualforce",
isredirect: "true"
});
urlEvent.fire();
}
});
In order to obtain the Account Id from the Opportunity, first you need to get the Opportunity Id where the Quick Action is being executed. That can be easily achieved by implementing the force:hasRecordId interface (in addition to the lightningQuickActionWithoutHeader one that you are already implementing). By doing this, you get access to recordId attribute which already contains the record id of the Opportunity in this case (https://developer.salesforce.com/docs/component-library/bundle/force:hasRecordId/documentation).
Once you get the Opportunity Id, you can use different methods to obtain the related Account's id. You can create an Apex Controller but you can also use the force:recordData component (https://developer.salesforce.com/docs/component-library/bundle/force:recordData/documentation) to obtain the Account Id.
<aura:component implements="force:lightningQuickActionWithoutHeader,force:hasRecordId">
<aura:attribute type="Opportunity" name="opportunity" />
<force:recordData
recordId="{!v.recordId}"
fields="AccountId"
targetFields="{!v.opportunity}"
/>
Are you sure you want to proceed?
<div class="slds-align_absolute-center">
<lightning:button
label="No"
variant="destructive"
onclick="{!handleNo}"
></lightning:button>
<lightning:button label="Yes" onclick="{!c.handleYes}"></lightning:button>
</div>
</aura:component>
Controller:
({
handleNo: function (component, event, helper) {
var accountId = component.get("v.opportunity.AccountId");
var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
url: "/apex/MyOtherVisualforce",
isredirect: "true"
});
urlEvent.fire();
},
handleYes: function (component, event, helper) {
var accountId = component.get("v.opportunity.AccountId");
var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
url: "/apex/MyVisualforce",
isredirect: "true"
});
urlEvent.fire();
}
});
Related
I'm trying to display the username in the navbar. I managed to do it using my profile service like this:
let user of profileService.getProfile(), which uses the subscribe in order to retrieve the data.
However, the first time that I log in the name won't pop out. If I refresh the browser, the name will be displayed. I guess that it has something to do with the subscribe and its asynchronous nature, but if that's the case, what would be the best solution to the problem?
As you mentioned in the comment your getProfile() returns an observable.
You can subscribe to it in your component and then display the user name in your HTML component:
userName: string;
constructor(private profileService: ProfileService){}
ngOnInit(): void {
this.profileService.getProfile().subscribe((resp)=>{
//Assuming response only returns username
this.userName = resp;
});
}
and then in your HTML you can just bind to userName.
<div>
Logged in user name is: {{userName}}
</div>
I think that you can create a BehaviorSubject in service, it has a method getValue() that give a current value :
user$ : BehaviorSubject<String> = new BehaviorSubject("");
setProfile() {
this.user$.next("newName");
}
getProfile(): string {
return this.user$.getValue();
}
In View, you can use a pipe (AsyncPipe) to subscribe observable like :
{{ userOfProfileService$ | async }}
However, you can also use Subject observable without getProfile() but just with AsyncPipe in view.
user$ : Subject<String> = new Subject();
I am attempting to validate a form field for an SCA (mont-blanc) site.
As I am not versed in SuiteScript code, but know Java, I simply need to know how to retrieve the POST value of a form field, so that I can do a check on the submission before submitting the form.
The below is not working - simply because I don't know the function / method to call to get the email address that is being submitted.
name: 'ContactUs',
create: function create( data ) {
try {
url = '<the-url>';
var email = nlapiGetContext.getEmail();
if (email.indexOf("qq.com") === -1) {
response = nlapiRequestURL(url, data);
responseCode = parseInt(respons...
To validate any field data you need to use client-script on the said record and based on your code and requirement, I think you want to validate Suitelet data(right?).
You can deploy client script on any record/suitelet and validate field data in saveRecord method. You can find client script help doc here.
Detecting the value in a data field in a submitted form is as simple as data['field_name']
In the above example - it would be:
name: 'ContactUs',
create: function create( data ) {
try {
url = '<the-url>';
**var email = data['email'];**
if (email.indexOf("qq.com") === -1) {
response = nlapiRequestURL(url, data);
responseCode = parseInt(respons...
I want to share some data from template to another template using Meteor. I have a template i.e allInventory.html on which i am showing some data in table form i added three links there that is. one for view , edit and delete what i want iam getting all the data from backend into one of helper i.e productDetails and i bind an event with view button that will take the data of current user clicked on which product so i have successfully getting the data at my allinventory template but there is another template i.e productDetails on which i want to render or show that data. But stuck with that i have data on allInventory click event but not know how do ishare the same with productDetails template.
Here is my allInventory.js
Template.allInventory.rendered = function() {
Template.allInventory.events({
"click .btn":function (e){
data = $(e.target).attr('data');
Router.go('productDetail', {data: $(e.target).attr('data')}, {query: 'q=s', hash: 'hashFrag'});
console.log("button clicked.."+data);
console.log(data);
}
})
ProductDetails.js
Template.productDetail.rendered = function () {
Template.productDetail.helpers({
productDetails: function() {
return data;
}
});
allInvenrtory.html
<button type="button" data ="{{productInfo}}" class="btn btn-info btn-sm"><i class="fa fa-eye"></i>View</button>
I just simply want to share allInventory template data with productsDetails template.
Any help would be appriciated!
Thanks
I'd recommend avoiding Session for this purpose, since it is a global object, but more importantly, because there are better ways to do it.
You can pass data from the parent templates to the child template using helpers: https://guide.meteor.com/blaze.html#passing-template-content
You can pass data from the child to the parent templates using callbacks https://guide.meteor.com/blaze.html#pass-callbacks
I'd structure this app to have a container (page) template, which will have all the subscriptions and render one of your templates based on the URL.
You can use the Session variable if you want to share data between templates.
You can follow this guide:
http://meteortips.com/first-meteor-tutorial/sessions/
I would put both template in a third, parent template.
ParentTemplate
-SharedInfo
-KidTemplate1
-KidTemplate2
Then having this third template hold the information you want to share across templates.
For that you can use a ReactiveVar, ensuring that change by template1 code on the parent template is visible in template2 as well.
To access the parent template for the kids, you can do something along those lines :
Blaze.TemplateInstance.prototype.parentTemplate = function (levels) {
var view = Blaze.currentView;
if (typeof levels === "undefined") {
levels = 1;
}
while (view) {
if (view.name.substring(0, 9) === "Template." && !(levels--)) {
return view.templateInstance();
}
view = view.parentView;
}
};
I'm creating a form for a DropDown like this:
#{
Html.BeginForm("View", "Stations", FormMethod.Get);
}
#Html.DropDownList("id", new SelectList(ViewBag.Stations, "Id", "Name"), new { onchange = "this.form.submit();" })
#{
Html.EndForm();
}
If I choose a value from my dropdown I get redirected to the correct controller but the URL is not as I would like to have it:
/Stations/View?id=f2cecc62-7c8c-498d-b6b6-60d48a862c1c
What I want is:
/Stations/View/f2cecc62-7c8c-498d-b6b6-60d48a862c1c
So how do I get the id= querystring parameter replaced by the more simple URL Scheme I want?
A form with FormMethod.Get will always post back the values of its form controls as query string values. A browser cannot generate a url based on your route configurations because they are server side code.
If you really wanted to generate /Stations/View/f2cecc62-7c8c-498d-b6b6-60d48a862c1c, then you could use javascript/jquery to build your own url and redirect
#using (Html.BeginForm("View", "Stations", FormMethod.Get))
{
#Html.DropDownList("id", new SelectList(ViewBag.Stations, "Id", "Name"))
}
var baseUrl = '#Url.Action("View", "Stations")';
$('#id').change(function() {
location.href = baseUrl + '/' $(this).val();
});
Side note: Submitting on the .change() event is not expected behavior and is confusing to a user. Recommend you add a button to let the user make their selection, check it and then submit the form (handle the button's .click() event rather that the dropdownlist's .change() event)
Remove "id"
from
#Html.DropDownList("id", new SelectList(ViewBag.Stations, "Id", "Name"), new { onchange = "this.form.submit();" })
In my productcontroller I have two actionresult returning methods:
[Route("Shop/{brand}/{category}/{subcategory?}/{page:int?}")]
public ActionResult Index(string brand, string category, string subcategory, int? page, SortOptions currentSort = SortOptions.SinceDesc)
{ //...
and
[HttpPost]
[Route("Shop/{brand}/{category}/{subcategory?}/{page:int?}")]
public ActionResult Index(ProductsViewModel pvm)
{ //...
And this is my razor view:
#using (#Html.BeginForm("Index", "Products", FormMethod.Post))
{
#Html.DropDownListFor(x => x.SubCatID, Model.SubCategoriesSelectList, new { #class = "multiselect" })
}
When I submit the page it hits the httppost method but the url is still: Shop/nike/shoes even when I selected the subcategory runningshoes from the dropdown.
I would like to have urls like:
shop/nike/shoes
shop/nike/shoes/runningshoes
Being more of a webform-guy I am having a hard time to navigate to new url's and using viewmodel properties as parameters.
edit posted my UI:
to explain my ui:
the first dropdown should get to a subcategory. for instance: shop/nike/shoes/runningshoes
The second should post 'back' to sort the products.
The price slider should post back because it should filter. (would filter client side if there was no paging)
The paging should get so you can deeplink to a certain page: shop/nike/shoes/runningshoes/page2 etc.
In your BeginForm(...) you end up having to pass a route values dictionary with Subcategory = "runningshoes"
This does mix values being passed by GET, aka in the querystring through the route values dictionary, and POST, which will be the values from the form, but will accomplish what you are trying to do. More can be read about the BeginForm(..) overload Here on MSDN
You should end up with:
#using (#Html.BeginForm("Index", "Products", new { subcategory = "runningshoes" }, FormMethod.Post))
{
#Html.DropDownListFor(x => x.SubCatID, Model.SubCategoriesSelectList, new { #class = "multiselect" })
}
EDIT
Just realized you want the value from the form post to be in the QueryString on the response. Instead of returning the view directly from your MVC method for the Form Post what you could possibly do is a return RedirectToAction("ActionName", "ControllerName", new { subcategory = request.SubCategory }); which you would have an action that would support this redirect specifically.
Additional information on redirect to action can be found here on MSDN