How to make list attachment mandatory in SharePoint 2007 - sharepoint

Anyone knows how to make attachment compulsory to the SharePoint custom list?
We are using SharePoint 2007.

There's nothing in the UI / Admin to do this AFAIK.
This arcticle explains how to achieve it with jQuery Link
Edited to correct my previous answer, which on reflection only provided a part answer. The above link is the correct way to achieve this. It shows the mechanism to query the attachments details on the NewForm, ie: before the list item is created, which is the point at which the mandatory function can be applied.

Add the below function as a script in a "Content Editor Web Part" or directly to the form via SharePoint designer. Obviously, this also requires jQuery.
function PreSaveAction(){
var hasAttachment = false;
//There are more then one fileupload inputs on the form
//and one of them will always be blank
$("input[name^='fileupload']").each(function() {
if ($(this).val() != "") {
hasAttachment = true;
}
});
if (hasAttachment){
return true; //OK to save
}else{
alert('An attachment is required!');
return false; //Prevents user from saving
}
}

Better Create a workflow
which will send a mail to last modified by + cc team lead
"if the current item has attachment = no" send mail

Related

Always open the default form in CRM on the case entity

We have two forms for the case entity. The default case form is heavily customized and has become rather slow to work with. The second form, called 'fastcase', is a lightweight version of the default case form. Both forms are being used by the same users. The fastcase form is opened from a link in SharePoint. We want that the default case form is always opened when working from within CRM.
I was wondering if, and how, it is possible to force CRM to always open the default case form when working from within CRM.
The only thing I could find was this link, but I have a feeling that the solution with navigate will also force the SharePoint fastcase form to open in the default case form. Working with different user roles and groups is also not an option as suggested there.
First of all: You are not using forms they are supposed to be used. Forms are role based and you are trying to use them for something else. Anyway, I totally understand your idea and I have been in the same situation :)
You need to do a little magic trick in CRM to make a form sticky. CRM stores the Most Recently Used (MRU) forms in a special entity called UserEntityUISettings. This entity stores UI settings per entity per user in xml.
What you need to do is to prevent CRM from changing this entity whenever the user changes the form for a given entity. Basically you want to control the attribute called lastviewedformxml. You can get some inspiration from this blog post: https://community.dynamics.com/crm/b/gonzaloruiz/archive/2014/11/19/avoiding-form-reload-when-switching-crm-forms-based-on-a-field.aspx
Happy coding...
You can open CRM forms in this way:
function OpenForm()
{
var parameters = {};
var id = GetFormId("account", "FormName");
parameters["formid"] = id;
Xrm.Utility.openEntityForm("account", null, parameters);
}
function GetFormId(formEntity, formName) {
var serverUrl = Xrm.Page.context.getServerUrl();
var oDataEndpointUrl = serverUrl + "/XRMServices/2011/OrganizationData.svc/";
oDataEndpointUrl += "SystemFormSet?$top=1&$filter=ObjectTypeCode eq '" + formEntity + "' and Name eq '" + formName + "'";
var service = new window.XMLHttpRequest;
var id;
if (service != null) {
service.open("GET", oDataEndpointUrl, false);
service.setRequestHeader("X-Requested-Width", "XMLHttpRequest");
service.setRequestHeader("Accept", "application/json, text/javascript, */*");
service.send(null);
var requestResults = eval('(' + service.responseText + ')').d;
if (requestResults != null && requestResults.results.length == 1) {
var rec = requestResults.results[0];
id = rec.FormId;
}
}
return id;
}
Depends the way you are calling the form from sharepoint you call the form you need and from CRM you let it handles in the native way.

Write the plugin when Selecting the lookup flied and according to filed selection Show/Hide Address filed in form.....?

We Have Contact Entities in contact Entitie one lookup filed company Name in that lookup having two values 1.Account and 2.Contact . When we are selecting contact show the address filed when we select account hide the address filed we needs to write the plugin to Execute that works. Kindly any one help me on the same.
Thanks!!
Rajesh Singh
First, if you need to make change on a form, you can't use plug-ins. Plug-ins are made for bussinees logics, like Update another record when the first one is created, make complex logic, etc...
What you need it is a javascript that executes on the OnLoad of the form and OnChange event in that OptionSet.
The lines you are looking for are:
function ShowField()
{
// The field is present on the form so we can access to its methods
var optionSet = Xrm.Page.getAttribute("custom_attribute");
if (optionSet == undefined)
{
return;
}
// The control is present on the form so we can access to its methods
var controlAddress = Xrm.Page.getControl("custom_address");
if (controlAddress == undefined)
{
return;
}
var valueOptionSet = optionSet.getValue(); // This is the value you set creating the OptionSet
switch (valueOptionSet)
{
case 0: // Your account value, show
controlAddress.setVisible(true);
case 1: // Your contact value, hide
controlAddress.setVisible(false);
default:
return;
}
}
You need to register a web resource and register the event, if you need more information about the code or why this stuff is here and why this not just tell me.

CRM form. Preset Field is not saved on after Clicking Save button

I am working on CRM 2011.
On Form_onLoad event I am presetting the value of a field.
mdg.PreSetField("address1_line1","Amsterdam");
but after clicking on save button my field address1_line1 is blank.
To check I put a alert on Form_onsave function.
alert("address =" + (Xrm.Page.getAttribute("address1_line1").getValue()));
In alert,I get the value of address1_line1 field but finally address1_line1 is blank.
mdg.PresetField function is as follows
mdg.PreSetField = function(attributeName, value) {
var attribute;
if (attributeName.setSubmitMode) {
attribute = attributeName;
}
else {
attribute = Xrm.Page.getAttribute(attributeName);
}
attribute.setSubmitMode('never');
attribute.setValue(value);
attribute.addOnChange(function() {
attribute.setSubmitMode('always');
});
};
I solved it..
in my custom mdg.PresetField function earlier code was
attribute.setSubmitMode('never');
I changed never to always and now it is working..
mdg.PreSetField("address1_line1","Amsterdam");
This code is not part of the CRM JavaScript API so I assume it's a custom library? Have you added this script to the list of webresources available on the form? Also make sure it comes before the script you are trying to use it in.

Accessing current user information for a netsuite html form using suitescript

I've been trying to figure auto-complete some values from netsuite onto our custom html form.
After a bit of researching, I found this gem: nlapiGetContext (http://www.netsuite.com/portal/developers/resources/APIs/Dynamic%20HTML/SuiteScriptAPI/MS_SuiteScriptAPI_WebWorks.1.1.html)
which should do exactly what it says,
However, when doing a console.log dump of nlapigetcontext()
the following information is displayed, not my current logged in user information
Here is my current test script:
if (window.addEventListener) { // Mozilla, Netscape, Firefox
window.addEventListener('load', WindowLoad, false);
} else if (window.attachEvent) { // IE
window.attachEvent('onload', WindowLoad);
}
function WindowLoad(event) {
alert(nlapiGetContext().getCompany());
console.log(nlapiGetContext());
}
Any help or guidance is appreciated!
Thank you!
Where is this form located? Context will only work if you are logged into the system, so this won't apply for online customer forms, those are considered to be "outside the system".
You can write a Suitelet to retrieve data from an external form if you are only retrieving values.
I use this to get campaign information on an external landing page.
function getCamData(request, response){
if ( request.getMethod() == 'GET' ){
response.setHeader('Custom-Header-CamID', 'CamID');
var camid = request.getParameter('camid');
var rec = nlapiLoadRecord('campaign', camid);
var o = new Object();
o.thisid = camid;
o.promocode = rec.getFieldValue('campaignid');
o.phone = rec.getFieldValue('custevent_cam_1300num');
o.family = rec.getFieldValue('family');
var myString = JSON.stringify(o);
response.write (myString);
}}
You request something like this:
https://forms.netsuite.com/app/site/hosting/scriptlet.nl?script=188&deploy=1&compid=xxxxxx&h=fb8224b74b24907a79e6&camid=8020
And returns something like this:
{"thisid":"8020","promocode":"CAM999","phone":"1800 111 222","family":"12"}
Also you can do server-side posting from an external site to a NetSuite customer online form, it will capture and validate the data as far as it has the entry fields set in NS, this is a great way to avoid using those horrible iframes.
Use these functions
nlapiGetContext().getName()
nlapiGetContext().getUser()
nlapiGetContext().getRole()
nlapiGetContext().getRoleId()
nlapiGetContext().getRoleCenter()
nlapiGetContext().getEmail()
nlapiGetContext().getContact()
nlapiGetContext().getCompany()
nlapiGetContext().getContact()
nlapiGetUser()
nlapiGetDepartment()
For details check http://suitecoder.appspot.com/static/api.html

Sharepoint List redirect with new id

I have a list within Sharepoint, using a custom new form I have added a custom list form control ("New item form" for the list) and changed the SaveButton to a standard input HTML button, and added an 'onclick' event that is as follows:
onclick="javascript: {ddwrt:GenFireServerEvent('__commit;__redirect={NewFormWizard2.aspx?id=}')}"
This works as in saves the data and redirects to the NewFormWizard2.aspx?id= page.
How do I get the ID of the created item to be passed to the redirected page?
Thus once the form is completed it would redirect to NewFormWizard2.aspx?id=23
jtherkel was close, but was missing a '}' on the end of the redirect url. I used an extra concat below
<input type="button" value="Submit" name="btnSave" onclick="javascript: {ddwrt:GenFireServerEvent(concat('__commit;__redirect={lists/MyListName/DispForm.aspx?ID=',/dsQueryResponse/Rows/Row/#ID,'}'))}" />
I am not sure where the ID will exist on the page you host the Javascript from. Does it appear in the querystring or on a field on the page?
There is nothing in the request or response that will identify the item. I have had this issue when doing some web loadtesting.
I can only suggest that your create the item using the webservices as that at gives you some return xml.
This answer does not solve the "new form" issue, but it might help others with the syntax for screens that contain existing list items.
I tested this quickly in my SharePoint (MOSS 2007) environment.
onclick="javascript: {ddwrt:GenFireServerEvent(concat('__commit;__redirect={NewFormWizard2.aspx?id=',/dsQueryResponse/Rows/Row/#ID))}"
The concat syntax is an XSLT instruction that tells the processor to combine the values enclosed in single quotes. I adapted this answer from info I found here.
Loading Values in a Custom List Form
http://wssdevelopment.blogspot.com/2007_04_01_archive.html
I hope this would be helpfull:
1- In SharePoint Designer create new page, call it for example "LastItem.aspx" and place a dataview on it with a single form view for the destination list item.
2-Limit paging to just one record, set the sorting by ID and descending and filter the list to just show item which is created by [current user].
3-Now you do not need to pass any query string to this page. just replace the default "OK" button in NewForm.aspx of the list with a standard HTML input button and add this to its definition "onclick="javascript: {ddwrt:GenFireServerEvent(concat('__commit;__redirect={LastItem.aspx}". After submitting a new item to list you will be redirected to an edit view of the created item.
You can do the same for save button in LastItem.aspx to redirect to some other page after clicking on save button.
found an approach using pure javascript (JQuery) and the SPAPI code from http://darrenjohnstone.net/.
The list contains two fields, title and BodyCopy
I've thewn created a form that asks for a title and a question, both text fields, then the submit button calls the following function: (note that ServerAddress and LIST_question need to be updated to your own details).
The function then uploads the details using the SOAP service within LISTS.ASMX and using the response gets the ID of the new item and redirects the page.
var LIST_question = '{xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}';
var ServerAddress = 'http://xxx/';
function submitQuestion()
{
var title = new String($("#title").val());
var t = new String($("#question").val());
t=t.trim();
if(t=="")
return;
title=title.trim();
if(title=="")
return;
var lists = new SPAPI_Lists(ServerAddress) ;
//
var newItem = { Title : title, BodyCopy : t};
var items = lists.quickAddListItem(LIST_question, newItem);
var id=-1;
if (items.status == 200)
{
var rows = items.responseXML.getElementsByTagName('z:row');
if(rows.length ==1)
{
var r = rows[0];
var id = r.getAttribute('ows_ID');
window.location.href='DispForm.aspx?ID='+id;
}
else
{
alert("Error: No row added");
}
}
else
{
alert('There was an error: ' + items.statusText);
return;
}
}
You can achieve this using JavaScript http://www.sharepointdrive.com/blog/Lists/Posts/Post.aspx?ID=9

Resources