I created a cms form field would like to get the value of it at runtime from the codebehind of one of my template classes. Is this possible?
Thanks in Advance
Here is your code:
using CMS.DataEngine;
using CMS.Helpers;
using CMS.OnlineForms;
using CMS.SiteProvider;.
...
...
...
var formInfo = BizFormInfoProvider.GetBizFormInfo("ContactUs", SiteInfoProvider.GetSiteInfo("mySiteID").SiteID);
var className = DataClassInfoProvider.GetDataClassInfo(formInfo.FormClassID).ClassName;
var data = BizFormItemProvider.GetItems(className);
if (!DataHelper.DataSourceIsEmpty(data))
{
foreach (var item in data)
{
var myFieldValue = item.GetStringValue("MyFieldColumnName", "");
}
}
You can find more info here.
This article by Kentico will solve your problem and have extensive article on using Bizform API.
https://docs.kentico.com/plugins/servlet/mobile#content/view/58331946
Related
I am trying not to have the column description for field type "URL" in SharePoint 2016. I want to use this OOTB column URL, but not get "Type the description". The only work around i saw is using JavaScript. I wanted to know, is there any other way remove it?
Programmatically, or some property in schema.xml?
Any suggestions and help is appreciated.
Thanks,
Menon
Sample JSlink script for you.
You could upload jQuery library and the custom jslink library to SharePoint library, I upload to layouts folder just for easy testing.
script:
(function () {
var JSHyperlinkFieldCtx = {};
JSHyperlinkFieldCtx.Templates = {};
JSHyperlinkFieldCtx.Templates.Fields = {
"JSHyperlink": {
"NewForm": HideJSHyperlinkTemplate
}
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(JSHyperlinkFieldCtx);
})();
function HideJSHyperlinkTemplate(ctx) {
var result = SPFieldUrl_Edit(ctx);
var $f = $(result);
$f.find('span:eq(1)').css('display', 'none');
$f.find('input:eq(1)').css('display', 'none');
return $f.html();
}
use the script:
~sitecollection/_layouts/15/jslinks/jquery-1.12.4.js|~sitecollection/_layouts/15/jslinks/HyperlinkField.js
I'm trying to perform people search in SharePoint online user profile from Sharepoint hosted app but it returns no data.
I'm using the following code to do this:
clientContext = new SP.ClientContext.get_current();
// Building Keyword query for the search
var keywordQuery = new Microsoft.SharePoint.Client.Search.Query.KeywordQuery(clientContext);
keywordQuery.set_queryText("mohammed");
keywordQuery.set_sourceId("B09A7990-05EA-4AF9-81EF-EDFAB16C4E31");
keywordQuery.set_rowLimit(500);
keywordQuery.set_trimDuplicates(false);
var searchExecutor = new Microsoft.SharePoint.Client.Search.Query.SearchExecutor(clientContext);
results = searchExecutor.executeQuery(keywordQuery);
clientContext.executeQueryAsync(
function () {
alert(results.m_value);
},
function (err) {
alert("Error");
}
);
I'm trying to search user profile which contains "mohammed" text.
searchExecutor.executeQuery(keywordQuery) executes without any error but results.m_value returns 0. If I get value from results.m_value then I can move towards reading UserProfile properties using PeopleManager
Note: I've user as Mohammed Arief Kannubasha
Anyone please advice, thanks in advance
Try this
keywordQuery.set_queryText("mohammed*");
I am using sharepoint CSOM to download / upload file from a OneDriveBusiness account.
Before downloading the file I need to check if the file is currently in use.
File.CheckOutType is alway "None".
I though using File.LockedByUser property, using the following code, but I got a ServerObjectNullReferenceException when the file is not locked.
var listItem = clientDocs.GetItemById(item.Id);
clientContext.Load(listItem.File.LockedByUser);
clientContext.ExecuteQuery();
var locked = listItem.File.LockedByUser.UserId;
I was hoping to be able to do do something like :
if (file."locked")
{
throw exception...
}
enter code here
Any idea ?
Thanks !
File.LockedByUser property is a deferred property, it need to be requested explicitly as demonstrated below:
var list = ctx.Web.Lists.GetByTitle(listTitle);
var listItem = list.GetItemById(itemId);
ctx.Load(listItem, i => i.File.CheckOutType, i => i.File.CheckedOutByUser, i => i.File.LockedByUser);
ctx.ExecuteQuery();
if(listItem.File.CheckOutType != CheckOutType.None) //Is checked out?
{
var checkoutUserName = listItem.File.CheckedOutByUser.LoginName;
var lockedUserName = listItem.File.LockedByUser.LoginName;
}
Background
I got a page where I’m showing two list views from two separate lists which both have Custom List as their ListTemplate. They got their separate jslink file cause I don’t want them to look alike.
Problem
The js link file targets both listviews since they use the same Template.
Code
(function () {
var listContext = {};
listContext.Templates = {};
listContext.ListTemplateType = 100;
listContext.Templates.Header = "<div><ul>";
listContext.Templates.Footer = "</ul></div>";
listContext.Templates.Item = LinkTemplate;
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(listContext);
})();
Question
Is there any way to make the js only target a specific list?
Ended up going with Paul Hunts solution that he writes about on myfatblog.co.uk. http://www.myfatblog.co.uk/index.php/2013/09/listview-web-part-issues-with-jslink-and-display-templates-a-solution/
The script ended up looking like this and I pasted it into the jslink function where I define what listContext to override.
// Override the RenderListView once the ClientTemplates.JS has been called
ExecuteOrDelayUntilScriptLoaded(function(){
// Copy and override the existing RenderListView
var oldRenderListView = RenderListView;
RenderListView = function(ctx,webPartID)
{
// Check the title and set the BaseViewId
if (ctx.ListTitle == "List")
ctx.BaseViewID = "list";
//now call the original RenderListView
oldRenderListView(ctx,webPartID);
}
},"ClientTemplates.js");
I am very confused, i am trying in vain to queue up multiple inserts i have thousands of adds to do so i only want to really do the database once.
I am using .net 4 and entity framework 4 and also added reference to system.data.objects
but i still have no overload available for SaveChanges
here is my code:
using (TransactionScope scope = new TransactionScope())
{
using (myDbContext context = new myDbContext)
{
foreach (var p in model)
{
var tempProduct = new Products();
// set a loopable list of available products
IEnumerable<MerchantProductFeedMerchantProd> prod = p.prod;
foreach (var i in prod)
{
var prodText = i.text.FirstOrDefault();
var prodUri = i.uri.FirstOrDefault();
var prodPrice = i.price.FirstOrDefault();
FillTempProduct(feedId, i, tempProduct, supplierId, feedInfo, prodPrice, prodText,
prodUri);
context.Products.Add(tempProduct);
context.SaveChanges(false); // no overload
}
scope.Complete();
context.AcceptAllChanges(); //acceptallchanges not referenced ??
}
}
this is really battering my head now, so any help would be much appreciated.
thanks
Because you are using DbContext API and these methods are from ObjectContext API. DbContext API is simplified = it is only for simple requirements. If you have more complex requirements you must use ObjectContext API by converting your DbContext to ObjectContext instance:
var objectContext = ((IObjectContextAdapter)myDbContext).ObjectContext;